How to upload large file(s) on FTP server using php?

天大地大妈咪最大 提交于 2020-01-24 10:17:05

问题


$ftp_server = 'ftp.abc.com';
$remote_file = "myvideo.avi";  // file size 210MB
$file = "myvideo.avi";        // file size 210MB
$conn_id = ftp_connect($ftp_server);  // set up basic connection

// login with username and password
$login_result = ftp_login($conn_id, 'faraz@abc.com', 'password');

ftp_pasv($conn_id, true); // turn passive mode on
// 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);

i already edit php.in for
upload_max_filesize = 1024M

above snippet working on all types of file(s) upload,
but when am trying to upload a large size file then it upload on server but size varies after uploading.
A video file size-210MB on local-machine
but after upload, it displayed file size 328KB on FTP-server.
i have no idea where do i check, if someone has suggestion then i appreciates


回答1:


Use FTP_BINARY instead of FTP_ASCII. The latter might stop at the first NUL byte.

Besides that, there is no good reason to use ascii mode nowadays, even for ascii files. The only case where it's important if you have cgi scripts containing a shebang line that have windows linebreaks locally.



来源:https://stackoverflow.com/questions/10153502/how-to-upload-large-files-on-ftp-server-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!