troubleshooting Question

How do I fix this ftp image upload script?  (It worked once!)

Avatar of rlb1
rlb1 asked on
PHP
2 Comments2 Solutions475 ViewsLast Modified:
Experts,
How do I fix this FTP image upload script?  I have worked on it for several hours, and it worked once.   I plan on incorporating this with a mysql database...

Now, I am receiving two errors:

Warning: fopen() [function.fopen]: Filename cannot be empty in /mnt/target02/347537/www.myurl.net/web/content/phpcode-keep/ftp_image.php on line 37

Warning: ftp_fput() expects parameter 3 to be resource, boolean given in /mnt/target02/347537/www.myurl.net/web/content/phpcode-keep/ftp_image.php on line 53
There was a problem while uploading

Any help to make this work would be appreciated!!!  
<?

/***********************************************
  Upload file to FTP
***********************************************/

//FTP Connection Information
$ftp_server = 'ftp.myurl.net';
$ftp_user_name = '$username';
$ftp_user_pass = '$password';

//Keep track of success or failure
$bFTPSuccess = false;

//Move file to the upload directory
move_uploaded_file($_FILES["file"]["tmp_name"], $_g['ROOT_PATH']."upload/" . $_FILES["file"]["name"]);

//Open the file

//fopen("http://www.courl.com/product-images/03170/200/03170a.jpg","r");

$file = $_FILES["http://www.courl.com/product-images/03170/200/03170a.jpg"]["03170a.jpg"];
$fp = fopen($file, 'r');


//$file = $_g['ROOT_PATH']."upload/" . $_FILES["file"]["name"];
//$fp = fopen($file, 'r');

//Connect to the FTP
$conn_id = ftp_connect($ftp_server);

//Login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

//If the file doesn't already exist on the FTP
if (ftp_size ($conn_id, $_FILES["file"]["name"]) == -1)
{
	//Try to upload $file
	if (ftp_fput($conn_id, $_FILES["file"]["name"], $fp, FTP_BINARY )) 
	{
		//echo "Successfully uploaded $file\n";
		$bFTPSuccess = true;
	} 
	else 
	{
		die("There was a problem while uploading $file\n");
	}
}
else
{
	die("File already exists!");
}

//Close the FTP connection and the file
ftp_close($conn_id);
fclose($fp);

//Delete the file from the upload directory
unlink($file);
 

?>
ASKER CERTIFIED SOLUTION
dsmile

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros