正在尝试从formData上载大文件

Trying upload large file from formData

本文关键字:上载 文件 formData      更新时间:2023-09-26

我尝试通过FormData和xmlHTTPRequest上传大文件(超过200mb),就像这个

var fd = new FormData;
fd.append('files[]', file);
xmlHttpRequest.open("POST", url, true);
xmlHttpRequest.send(fd);

在php脚本中,我有

<?php
var_dump("IN");
var_dump($_FILES);

out:

IN
array()

请求等待10秒并完成。有了较小的文件一切都好,没有FormData(来自的简单ajax)一切都好。php.ini中的所有设置都具有最大值。怎么了?

如果可以的话,这是我的请求头:

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Cache-Control no-cache
Content-Length 294561150
Content-Type multipart/form-data
Host test1
Referer http://test1/
User-Agen Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
X-Requested-With XMLHttpRequest

响应标头:

Connection close
Content-Encodin gzip
Content-Length 51
Content-Type text/html
Date Sat, 29 Jun 2013 23:03:26 GMT
Server Apache/2.2.22 (Ubuntu)
Vary Accept-Encoding
X-Powered-By PHP/5.4.17RC1

我的/etc/php5/apache2/php.ini:

file_uploads = On
upload_max_filesize = 512M
max_file_uploads = 20
max_input_time = 10000
memory_limit = 2048M
max_execution_time = 10000
post_max_size = 1024M

我的脚本链接:http://www.megafileupload.com/en/file/430866/test1-tar-gz.html

PS它一直运行10秒然后结束。

如果没有看到php.ini文件,这些都会影响上传,您需要相应地更改

file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time 
post_max_size

对于较大的文件,所有这些设置都必须具有相当高的设置。注意不要把你的记忆力限制得太高,这可能很危险。我可能会做128MBmax_execution_time被许多人遗忘,默认为30秒。不够长,无法容纳大文件。我将我的设置为1000,因为我处理大型视频。这是脚本没有完成并且将提前完成的常见原因。您可能需要也可能不需要重新启动web服务器。