我在PHP這樣的功能:PHP FTP上傳功能
function UploadFileToFTP($local_path, $remote_path, $file, $filename) {
global $settings;
$remote_path = 'public_html/'.$remote_path;
$ftp_server = $settings["IntegraFTP_H"];
$ftp_user_name = $settings["IntegraFTP_U"];
$ftp_user_pass = $settings["IntegraFTP_P"];
//first save the file locally
file_put_contents($local_path.$filename, $file);
//login
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// check connection
if((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
}
//change directory
ftp_chdir($conn_id, $remote_path);
$upload = ftp_put($conn_id, $filename, $local_path.$filename, FTP_BINARY);
// check upload status
if(!$upload) {
echo "FTP upload has failed!";
}
// close the FTP stream
ftp_close($conn_id);
}
我在這裏把它稱爲:
UploadFileToFTP('p/website/uploaded_media/', 'media/', $_FILES["file"]["tmp_name"], $filename);
所選文件被移動到本地目錄,也被上傳但是到FTP該文件由於沒有正確上傳而變得腐敗。
我怎樣才能正確地上傳文件?
我剛換到FTP_ASCII,但它仍然在做同樣的事情。這些文件通常是圖像文件 – charlie
更可能需要以其他方式切換 – symcbean