尝试从formData上传大文件

时间:2013-06-29 22:38:05

标签: php javascript ajax xmlhttprequest form-data

我尝试通过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);

出:

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秒,然后完成。

1 个答案:

答案 0 :(得分:1)

如果没有看到你的php.ini文件,这些内容会影响上传,你需要相应地更改它们

file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time 
post_max_size

对于较大的文件,所有这些设置都必须具有相当高的设置。不要让你的记忆限制太高,这可能是危险的。我可能会做128MB。许多人忘记了max_execution_time,默认值为30秒。对于大文件来说不够长。自从我处理大型视频以来,我将我设置为1000。脚本没有完成并且过早完成的常见原因。您可能需要或不必重新启动Web服务器。