我正在尝试将上传的文件移动到远程服务器上,但这不起作用;
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);
我得到这个erorr;
警告:ftp_put()[function.ftp-put]:无法打开该文件:第52行/home/file/public_html/uploaded.php中的目录
答案 0 :(得分:3)
当$remote_file
变量指向文件时,它指向一个目录。尝试将$ remote_file更改为$remote_file = "/public_html/test/uploads/".$file;
答案 1 :(得分:1)
您应该将上传文件的部分包装在if语句中,该语句检查您是否实际连接到FTP
此外,在上传文件时,您需要文件1和文件2.现在您已经提供了文件2和目录。
答案 2 :(得分:1)
您要迁移的文件是目录"/public_html/test/uploads/"
,您需要将文件名和扩展名附加到目录中。
答案 3 :(得分:0)
添加 pasv_promiscuous = YES