使用 PHP 上传大于 2GB 的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4614147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uploading a file larger than 2GB using PHP
提问by Reado
I'm trying to upload a file larger than 2GB to a local PHP 5.3.4 server. I've set the following server variables:
我正在尝试将大于 2GB 的文件上传到本地 PHP 5.3.4 服务器。我设置了以下服务器变量:
memory_limit = -1
post_max_size = 9G
upload_max_filesize = 5G
However, in the error_log I found:
但是,在 error_log 中我发现:
PHP Warning: POST Content-Length of 2120909412 bytes exceeds the limit of 1073741824 bytes in Unknown on line 0
PHP 警告:2120909412 字节的 POST Content-Length 超出第 0 行未知中 1073741824 字节的限制
Can anyone tell me why this keeps failing please?
谁能告诉我为什么这总是失败?
采纳答案by regilero
Maybe this can come from apache limitations on POST size:
也许这可能来自 Apache 对 POST 大小的限制:
http://httpd.apache.org/docs/current/mod/core.html#limitrequestbody
http://httpd.apache.org/docs/current/mod/core.html#limitrequestbody
It seems this limitation on 2Gb can be greater on 64bits installations, maybe. And i'm not sure setting 0 in this directove does not reach the compilation limit. see for examples that thread:
在 64 位安装上,2Gb 的这种限制似乎可能更大。而且我不确定在这个指令中设置 0 不会达到编译限制。请参阅该线程的示例:
http://ubuntuforums.org/archive/index.php/t-1385890.html
http://ubuntuforums.org/archive/index.php/t-1385890.html
Then do not forget to alter as well the max_input_time in PHP.
然后不要忘记更改 PHP 中的 max_input_time。
But you are reaching high limits :-) maybe you could try a rich client (flash? js?) on the browser side, doing the transfer in chunks or some sort of FTP things, with progress indicators for the user.
但是您达到了很高的限制:-) 也许您可以在浏览器端尝试一个富客户端(flash?js?),以块或某种 FTP 方式进行传输,并为用户提供进度指示器。
回答by Mobiler
I had a similar problem, but my config was:
我有类似的问题,但我的配置是:
post_max_size = 1.8G
upload_max_filesize = 1.8G
and yet I could not upload a 1.2GB file. The error was very same:
但我无法上传 1.2GB 的文件。错误非常相同:
PHP Warning: POST Content-Length of 1347484420 bytes exceeds the limit of 1073741824 bytes in Unknown on line 0
I spent a day wondering where the heck was this "limit of 1073741824" coming from!
我花了一天的时间想知道这个“1073741824 的限制”到底是从哪里来的!
Solution:
解决方案:
Actually, the error was in the php.ini parser: It only understands INTEGER numbers, so essentially it was parsing 1.8G
as 1G
!!
实际上,错误出在 php.ini 解析器中:它只识别整数,所以本质上它解析1.8G
为1G
!!
Changing the value to e.g. 1800M
fixed it.
将值更改为例如1800M
修复它。
Pls ensure to restart the apache server with the below command service apache2 restart
请确保使用以下命令重新启动 apache 服务器service apache2 restart
回答by phliKtid
I don't know about in 5.3.x, but in 5.2.x there are some int/long issues in the PHP code. even if you're on a 64-bit system and have a version of PHP compiled with 64-bit, there are several problems.
我不知道在 5.3.x 中,但在 5.2.x 中,PHP 代码中存在一些 int/long 问题。即使您在 64 位系统上并且有一个用 64 位编译的 PHP 版本,也有几个问题。
First, the code that converts post_max_size and others from ascii to integer stores the value in an int, so it converting "9G" and putting the result into this int will bork the value because 9G is a larger number than a 32-bit variable can hold.
首先,将 post_max_size 和其他从 ascii 转换为整数的代码将值存储在一个 int 中,因此它转换“9G”并将结果放入这个 int 会导致该值,因为 9G 是一个比 32 位变量更大的数字抓住。
But there are also several other areas of PHP code that are used with the Apache module, CGI, etc. that need to be changed from int to long.
但是还有其他几个与 Apache 模块、CGI 等一起使用的 PHP 代码区域需要从 int 更改为 long。
So...for this to work, you need to edit the PHP code and compile it by hand (make sure you compile it as 64-bit). here's a link to a list of diffs:
所以...要使其工作,您需要编辑 PHP 代码并手动编译(确保将其编译为 64 位)。这是差异列表的链接:
http://www.archive.org/~tracey/downloads/patches/karmic-64bit-post-large-files.patch
http://www.archive.org/~tracey/downloads/patches/karmic-64bit-post-large-files.patch
Referenced from this php bug post: http://bugs.php.net/bug.php?id=44522
引用自此 php 错误帖子:http: //bugs.php.net/bug.php?id=44522
The file above is a diff on 5.2.10 code, but I just made the changes by hand to 5.2.17 code and i just uploaded a 3.4gb single file through apache/php (which hadn't worked before the change).
上面的文件是 5.2.10 代码的差异,但我只是手动对 5.2.17 代码进行了更改,并且我刚刚通过 apache/php 上传了一个 3.4gb 的单个文件(在更改之前没有工作)。
ope that helps.
打开有帮助。
回答by Fueled
As phliKtid mentioned, this is a limitation with the PHP framework. Save for editing the source code as mentioned in the bug reportphliKtid linked, there is a workaround that involves setting the upload_max_filesize
to 0 in the php.ini file.
正如 phliKtid 所提到的,这是 PHP 框架的一个限制。除了phliKtid 链接的错误报告中提到的编辑源代码之外,还有一种解决方法是upload_max_filesize
将 php.ini 文件中的设置为 0。
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 0
By doing this, PHP will not crash when trying to convert "5G" into a 32-bit integer and you will be able to upload files as big as you allow with the "post_max_size" variable.
通过这样做,PHP 在尝试将“5G”转换为 32 位整数时不会崩溃,并且您将能够使用“post_max_size”变量上传尽可能大的文件。
回答by bronze man
I figure out how to use http and php to upload a 10G file.
我弄清楚如何使用 http 和 php 上传 10G 文件。
php.ini:
php.ini:
post_max_size = 0
upload_max_filesize = 0
It works in php 5.3.10.
它适用于 php 5.3.10。
if you do not load that file all into memory , memory_limit is unrelated.
如果您不将该文件全部加载到内存中,则 memory_limit 无关。
回答by Michael Monnerie
We've had the same problem: uploads stopped at 2GB.
我们遇到了同样的问题:上传在 2GB 时停止。
Under SLES (SUSE Linux Enterprise Server) 11 SP 2, php53 was the problem.
在 SLES (SUSE Linux Enterprise Server) 11 SP 2 下,php53 是问题所在。
Then we added a new repository that has php54: http://download.opensuse.org/repositories/server:/php/SLE_11_SP2/
然后我们添加了一个具有 php54 的新存储库:http: //download.opensuse.org/repositories/server:/php/SLE_11_SP2/
and upgraded to that, we now can upload 5GB :-)
并升级到那个,我们现在可以上传 5GB :-)