如何在FTP服务器上使用PHP上传大文件? [英] How to upload large file(s) on FTP server using php?

查看:211
本文介绍了如何在FTP服务器上使用PHP上传大文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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


上面的代码片段处理所有类型的文件上传,

,但是当我试图上传一个大尺寸的文件,然后上传到服务器上,但上传后大小变化。

本地机器上的视频文件大小-210MB

,但是上传后,它在FTP服务器上显示的文件大小为328KB。

i不知道我在哪里检查,如果有人有建议,那么我赞赏

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

推荐答案

使用 FTP_BINARY 而不是 FTP_ASCII 。后者可能会停在第一个NUL字节。

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

除此之外,现在没有理由使用ascii模式,即使是ascii文件。只有在 的情况下,如果您的cgi脚本包含一个在本地具有windows linebreaks的shebang行,这一点很重要。

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.

这篇关于如何在FTP服务器上使用PHP上传大文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆