简体   繁体   中英

Moving an uploaded file onto a remote server

I am trying to move an uploaded file onto a remote server, this isn't working;

move_uploaded_file($tmp_name, "uploads/$code1/$code.$fileex");

$ftp_server = "IP";
$ftp_user_name = "username";
$ftp_user_pass = "password";
$file = $tmp_name;
$remote_file = "/public_html/test/uploads/";

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
 echo "successfully uploaded $file\n";
} else {
 echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);

I get this erorr;

Warning: ftp_put() [function.ftp-put]: Can't open that file: Is a directory in /home/file/public_html/uploaded.php on line 52

Your $remote_file variable is pointing to a directory when it should point to a file. Try changing $remote_file to $remote_file = "/public_html/test/uploads/".$file;

You should probably wrap the portion that uploads the file in an if statement that checks to see if you are actually connected properly to the FTP

Also, when uploading a file, you need file 1 and file 2. Right now you've supplied file 2 and a directory.

http://php.net/manual/en/function.ftp-put.php

您要移动到的文件是目录"/public_html/test/uploads/" ,您需要将文件名和扩展名附加到该目录中。

Add the following line at the end of the /etc/vsftpd.conf file

Add pasv_promiscuous=YES it

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