2016-05-19 51 views
0

我正在使用PHP創建一個導出文件。文件創建後,我希望將其移動到另一個ftp位置。文件創建順利,ftp連接似乎也很順利,但傳輸/上傳文件會導致錯誤。PHP:使用ftp_put導致錯誤,如何找到原因?

我已經檢查了使用Filezilla的憑據和路徑,並相信FTP路徑是好的。

這段代碼出了什麼問題,或者如何從代碼中獲得更多反饋以找出導致錯誤的原因?

這是代碼的一部分。我把它撿起來的文件創建完成後(所以這一切都發生在同一個文件):

fclose($myfile); 

$conn->close(); 

//Move file to ftp-server 
$ftp_server = "ftp.domain.com"; 
$ftp_username = "username"; 
$ftp_userpass = "password"; 
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server"); 
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass); 
$remote_location = "/public_html/testdir"; 
$file = "export.csv"; 

// upload file 
if (ftp_put($ftp_conn, $remote_location, $file, FTP_ASCII)) 
    { 
    echo "Successfully uploaded $file."; 
    } 
else 
    { 
    echo "Error uploading $file."; 
    } 

// close connection 
ftp_close($ftp_conn); 

所以我得到的錯誤是:「錯誤上傳export.csv。」該文件存在於運行代碼的php文件所在的目錄中。

請溫柔...

+0

您是否啓用了PHP警告「/public_html/testdir/example.csv」?你有訪問服務器日誌嗎? –

回答

1

據我所知,ftp_put接受第二個參數是在你的例子作爲文件名不是一個目錄/文件夾名稱$ remote_location。所以這個變量

$remote_location = "/public_html/testdir"; 

假設「/ public_html/testdir」是一個目錄是無效的。

因此,你應該改變它指向一個文件:

問候

相關問題