$ftp=ftp_connect(“ftp.mywebsite.com”);
$login_result=ftp_login($ftp, “admin”, “adminpassword”);
$file = $_FILES["uploadfile"]["name"];
$fp = fopen($file, 'r');
if(ftp_fput($ftp, $file,$fp, FTP_BINARY))
{ echo "success"; }
else { echo "error"; }
ftp_close($ftp);
fclose($fp);
I have made this script the php.net site and all i need now is t开发者_如何学运维o figure out how to get the users file to the ftp server not the one on my server. I was thinking I might need to upload their file to mine then from there to the ftp server any way here the code
$file = $_FILES["uploadfile"]["name"];
That's just the name of the file as it was provided by the client. Once uploaded, PHP stores it in a temporary file with a random name, which you access via the ['tmp_name']
attribute of the $_FILES array.
If you'd checked if the fopen() had succeeded (which it didn't), you'd have solved yourself this debugging problem:
$file = $_FILES['uploadfile']['tmp_name'];
$fp = fopen($file, 'rb') or die("Unable to open $file for reading");
if (ftp_fput(...)) {
etc...
}
精彩评论