FTP Uploader using php

2019-05-29 05:48发布

问题:

I am making a ftp image upload using jquery and php i am using ajax to send the data. I have the following code but its not working i am getting the following error.

Error:

Warning: ftp_put() [function.ftp-put]: httpdocs/user_images/: Not a regular file in /var/www/vhosts/kbba.biz/httpdocs/admin/php/upload.php on line 21

This is the tmp_name: /tmp/phpQbG3el

Code:

$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

ftp_put($conn_id, "httpdocs/user_images/", $_FILES['fileToUpload']['tmp_name'], FTP_BINARY); 

print_r($_FILES['fileToUpload']['tmp_name']);

ftp_close($conn_id);

回答1:

You need to add a file name to the remote path like so:

ftp_put($conn_id, "httpdocs/user_images/" . $_FILES['fileToUpload']['name'], $_FILES['fileToUpload']['tmp_name'], FTP_BINARY);

This would be the outcome if I upload myfile.txt

ftp_put($conn_id, "httpdocs/user_images/myfile.txt","/tmp/phpQbG3el", FTP_BINARY);


标签: php upload ftp