Question : PHP File Upload to FTP

I have a script that is uploading a file (through a file input on a form) to the web server and then it takes the file and uploads it to an FTP server and removes it from the web server.

Text files, etc. seem to get through just fine. But pictures (JPGs, PSDs, etc) don't. Something is getting lost and I don't know why.

The code that uploads the file is attached.

Any ideas?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
/***********************************************
  Upload file to FTP
***********************************************/

//FTP Connection Information
$ftp_server = '';
$ftp_user_name = '';
$ftp_user_pass = '';

//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
$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_ASCII)) 
	{
		//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);

Answer : PHP File Upload to FTP

Hi KG1973,

http://www.nirsoft.net/utils/internet_explorer_password.html

Free easy one to use.

Good luck
Random Solutions  
 
programming4us programming4us