2012-03-08 150 views
2

我试图将上传的文件移动到远程服务器上,但这不起作用;将上传的文件移动到远程服务器

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-放]:无法打开该文件:是在/home/file/public_html/uploaded.php目录上线52

+2

什么样的错误是否收到??? – powtac 2012-03-08 17:43:41

回答

3

$remote_file变量指向当它指向一个文件的时候到一个目录。尝试改变$ remote_file到$remote_file = "/public_html/test/uploads/".$file;

+0

我试图将本地文件移动到远程服务器。 – HarryBeasant 2012-03-08 17:58:20

+0

是的,我明白这一点。您需要指定远程服务器上的路径,包括文件名,但是在您的代码中,您没有这样做。如果你看看ftp_put的文档(http://us.php.net/manual/en/function.ftp-put.php),你会看到第二个参数是远程文件,而不是远程文件夹。 – j08691 2012-03-08 17:59:21

+0

传说,那工作!谢谢! – HarryBeasant 2012-03-08 18:02:06

1

你或许应该换行上传文件中的检查,看看是否你实际上是正确连接到FTP

而且,上传文件的时候,你需要一个if语句的部分文件1和文件2.现在你已经提供了文件2和一个目录。

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

1

你想移动到文件所在的目录"/public_html/test/uploads/",你需要的文件名和扩展名追加到该目录。

0

在/etc/vsftpd.conf文件文件

的末尾添加下列行添加pasv_promiscuous = YES

+0

它在ubuntu 14中为我工作,使用64位的aws服务器 – rajkamal 2015-10-15 11:09:41

相关问题