2012-03-08 148 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