简体   繁体   中英

Unable to upload image file using FTP

As the first step FTP connection and login both work. Then I tried

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

and able to see test folder in the results.

in addition, I checked for directory existence using ftp_chdir and it seems okay,

ftp_chdir($ftpcon, "test")

finally I am trying to upload an image (png) using,

$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,

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.

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!';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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