开发者

Unable to Upload An Image File Onto The FTP Server in php

开发者 https://www.devze.com 2023-02-18 21:16 出处:网络
$ftp=ftp_connect(“ftp.mywebsite.com”); $login_result=ftp_login($ftp, “admin”, “adminpassword”);
$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...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消