Link to home
Start Free TrialLog in
Avatar of rlb1
rlb1

asked on

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

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);
 

?>

Open in new window

SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial