【问题标题】:Trying upload large file from formData尝试从 formData 上传大文件
【发布时间】:2013-06-27 10:41:28
【问题描述】:

我尝试像这样通过 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 秒,然后结束。

【问题讨论】:

  • 您说 PHP.ini 中的所有设置都有最大值,但我们怎么知道您设置了正确的设置?发布您更改的 php.ini 设置。

标签: php javascript ajax xmlhttprequest form-data


【解决方案1】:

没有看到你的 php.ini 文件,这些都是会影响上传的东西,你需要相应地改变它们

file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time 
post_max_size

对于较大的文件,所有这些设置都必须具有相当高的设置。注意不要让你的 memory_limit 太高,这可能很危险。我可能会做128MBmax_execution_time 被许多人遗忘,默认为 30 秒。对于大文件来说不够长。因为我处理大型视频,所以我将我的设置为1000。这是脚本未完成并将过早完成的常见原因。您可能需要也可能不需要重新启动 Web 服务器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-30
    • 2017-09-06
    • 1970-01-01
    • 2011-09-17
    相关资源
    最近更新 更多