简体   繁体   English

使用PHP上传大于2GB的文件

[英]Uploading a file larger than 2GB using PHP

I'm trying to upload a file larger than 2GB to a local PHP 5.3.4 server. 我正在尝试将大于2GB的文件上传到本地PHP 5.3.4服务器。 I've set the following server variables: 我设置了以下服务器变量:

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警告:POST内容长度2120909412字节超过了第0行的Unknown中1073741824字节的限制

Can anyone tell me why this keeps failing please? 谁能告诉我为什么这会一直失败呢?

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. 然而我无法上传1.2GB文件。 The error was very same: 错误非常相似:

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解析器中:它只能理解INTEGER数字,所以基本上它将1.8G解析为1G !!

Changing the value to eg 1800M fixed it. 将值更改为例如1800M修复它。

Pls ensure to restart the apache server with the below command service apache2 restart 请确保使用以下命令service apache2 restart重新启动 apache服务器

I don't know about in 5.3.x, but in 5.2.x there are some int/long issues in the PHP code. 我在5.3.x中不知道,但在5.2.x中,PHP代码中存在一些int / long问题。 even if you're on a 64-bit system and have a version of PHP compiled with 64-bit, there are several problems. 即使您使用的是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. 但是还有一些PHP代码的其他区域与Apache模块,CGI等一起使用,需要从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). 所以...为了实现这一点,你需要编辑PHP代码并手动编译(确保将其编译为64位)。 here's a link to a list of diffs: 这是一个差异列表的链接:

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 bug帖子中引用: 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. 有帮助的ope。

Maybe this can come from apache limitations on POST size: 也许这可以来自POST大小的apache限制:

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. 似乎对64G安装的2Gb的这种限制可能更大。 And i'm not sure setting 0 in this directove does not reach the compilation limit. 而且我不确定在此指令中设置0是否达不到编译限制。 see for examples that thread: 看一下线程的例子:

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进行传输,并为用户提供进度指示器。

As phliKtid mentioned, this is a limitation with the PHP framework. 正如phliKtid所说,这是PHP框架的一个限制。 Save for editing the source code as mentioned in the bug report phliKtid linked, there is a workaround that involves setting the upload_max_filesize to 0 in the php.ini file. 保存用于编辑错误报告 phliKtid链接中提到的源代码,有一种解决方法,涉及在php.ini文件中将upload_max_filesize设置为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”变量上传文件大小。

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是无关的。

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 :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM