简体   繁体   English

无法使用 FTP 上传图像文件

[英]Unable to upload image file using FTP

As the first step FTP connection and login both work.作为第一步 FTP 连接和登录都工作。 Then I tried然后我尝试了

$file_list = ftp_nlist($ftpcon, ".");
var_dump($file_list);

and able to see test folder in the results.并且能够在结果中看到test文件夹。

in addition, I checked for directory existence using ftp_chdir and it seems okay,此外,我使用ftp_chdir检查了目录是否存在,看起来还可以,

ftp_chdir($ftpcon, "test")

finally I am trying to upload an image (png) using,最后我正在尝试使用上传图像(png),

$remote_dir = 'test/';
$src_file = $_FILES['srcfile']['name'];
$remote_file_path = $remote_dir . $src_file;

if (ftp_put($ftpcon, $remote_file_path, $src_file, FTP_BINARY))
    echo 'File uploaded successfully';
else
    echo 'Error uploading file!';

but getting a warning and Error uploading file message,但收到警告和Error uploading file消息,

ftp_put(image.png): Failed to open stream: No such file or directory

Can anyone point out what I am missing谁能指出我错过了什么

Thanks to @Guido Faecke and @MartinPrikryl for pointing me out, name should be used for the remote path, and tmp_name should be used for the file path.感谢@Guido Faecke 和@MartinPrikryl 指出, name应该用于远程路径, tmp_name应该用于文件路径。

The correction would be,更正将是,

$remote_dir = 'test/';
$src_name = $_FILES['srcfile']['name'];
$remote_file_path = $remote_dir . $src_name;

$temp_file_path = $_FILES['srcfile']['tmp_name'];

if (ftp_put($ftpcon, $remote_file_path, $temp_file_path, FTP_BINARY))
    echo 'File uploaded successfully';
else
    echo 'Error uploading file!';

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

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