2016-12-30 77 views
2

我想將上傳的文件移動到遠程服務器,但ftp_put()函數有錯誤。錯誤是:ftp_put() - 無法將文件移動到遠程服務器

Warning: ftp_put(C:\xampp\tmp\php1296.tmp): 
failed to open stream: No such file or directory in 
C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 65 
There was a problem while uploading C:\xampp\tmp\php1296.tmp 

我可能知道如何解決這個問題?

發現新的錯誤:

Warning: ftp_put(): Prohibited file name: 
/public_html/procurement/uploads/C:\xampp\tmp\php1A14.tmp in 
C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 69 
There was a problem while uploading C:\xampp\tmp\php1A14.tmp 

下面是我做了修訂

使用正確的答案代碼:

$temp_fpath = $_FILES['slip_gaji']['tmp_name']; 
$fname = date('d-m-Y-H-i-s') . '-' . $_FILES['slip_gaji']['name']; 

$ftp_server = "ftp.domain.com.my"; 
$ftp_user_name = 'myusername'; 
$ftp_user_pass = 'mypassword'; 
$file = $temp_fpath; 
$remote_file = "/public_html/procurement/uploads/" . $fname; 

// set up a connection or die 
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// login with username and password 
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// turn passive mode on 
ftp_pasv($conn_id, true); 

// upload a file 
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) { 
    echo "successfully uploaded $file\n"; 
} else { 
    echo "There was a problem while uploading $file\n"; 
} 

// close the connection 
ftp_close($conn_id); 

回答

1

問題是,C:\ xampp \ tmp \ php1296.tmp不存在。

在/ tmp/PHP *當您提交網頁的形式,與move_upload_file功能toghether使用結束

要你必須知道的路徑使用ftp_put文件通常產生的,它們一旦腳本刪除的文件。

+0

這意味着,我必須使用''$ file = uploads /「。 $ fname;'=>文件存在的位置或者我必須插入完整路徑=>''intranet/procurement/admin_cuti/slip-gaji/uploads /".$ fname;'? – Amran

+0

該文件與運行的腳本相關。 –

+0

第一個選項應該訣竅 –