Moving an uploaded file onto a remote server

2019-04-14 03:33发布

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

标签: php ftp
4条回答
Lonely孤独者°
2楼-- · 2019-04-14 03:43

The file you are trying to move to is the directory "/public_html/test/uploads/", you need to append the filename and extension onto the directory.

查看更多
疯言疯语
3楼-- · 2019-04-14 03:51

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;

查看更多
走好不送
4楼-- · 2019-04-14 03:53

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

Add pasv_promiscuous=YES it

查看更多
仙女界的扛把子
5楼-- · 2019-04-14 04:01

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

查看更多
登录 后发表回答