简体   繁体   English

无法将图像文件上传到PHP中的FTP服务器上

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

$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 to figure out how to get the users file to the ftp server not the one on my server. 我已经将此脚本制作为php.net站点,现在我所需要的只是弄清楚如何将用户文件传输到ftp服务器而不是服务器上的该文件。 I was thinking I might need to upload their file to mine then from there to the ftp server any way here the code 我在想我可能需要将其文件上传到我的文件,然后从那里以任何方式将其上传到ftp服务器

$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. 上传后,PHP将其存储在带有随机名称的临时文件中,您可以通过$ _FILES数组的['tmp_name']属性进行访问。

If you'd checked if the fopen() had succeeded (which it didn't), you'd have solved yourself this debugging problem: 如果您检查fopen()是否成功(但没有成功),则可以解决以下调试问题:

$file = $_FILES['uploadfile']['tmp_name'];
$fp = fopen($file, 'rb') or die("Unable to open $file for reading");
if (ftp_fput(...)) {
  etc...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM