使用PHP进行大型文件上载错误

时间:2022-03-04 07:01:16

I have an image upload for a slideshow, and the users are continuously uploading files that are 2MB plus. Files under this size work fine, but files over the size cause what looks like a browser timeout.

我有幻灯片显示的图片上传,用户不断上传2MB以上的文件。此大小的文件工作正常,但超过该大小的文件会导致浏览器超时。

Here are my php ini settings:

这是我的php ini设置:

  • Max memory allocation: 12M
  • 最大内存分配:12M

  • Max file upload size: 10M
  • 最大文件上传大小:10M

  • Max HTTP Post size: 10M
  • 最大HTTP帖子大小:10M

  • Max execution time: 60
  • 最长执行时间:60

  • Max input parsing time: 120
  • 最大输入解析时间:120

These settings are in the configuration file itself, and I can change them directly. Changes show up when using phpinfo().

这些设置在配置文件中,我可以直接更改它们。使用phpinfo()时会出现更改。

I am running on an apache server and php 4.3.9(client's choice, not mine). The apache server's request limit is set to default, which I believe is somewhere around 2GB?

我正在运行apache服务器和php 4.3.9(客户端的选择,而不是我的)。 apache服务器的请求限制设置为默认值,我相信它大概是2GB左右?

When I use the firebug network monitor, it does look like I am not receiving a full response from the server, though I am not too experienced at using this tool. Things seem to be timing out at around 43 seconds.

当我使用firebug网络监视器时,看起来我没有收到服务器的完整响应,尽管我对使用此工具的经验不太熟悉。事情似乎在43秒左右超时。

All the help I can find on the net points to the above settings as the culprits, but all of those settings are much higher than this 2MB file and the 43 second time out.

我可以在网上找到的所有帮助都指向上述设置作为罪魁祸首,但所有这些设置都比这个2MB文件和43秒超时要高得多。

Any suggestions at where I can go from here to solve this issue?

我可以从这里找到解决这个问题的任何建议吗?

Here are relevant php ini settings from phpinfo(). Let me know if I need to post any more.

以下是phpinfo()的相关php ini设置。如果我需要发布,请告诉我。

  • file_uploads On On
  • file_uploads On On

  • max_execution_time 60 60
  • max_execution_time 60 60

  • max_input_nesting_level 64 64
  • max_input_nesting_level 64 64

  • max_input_time 120 120
  • max_input_time 120 120

  • memory_limit 12M 12M
  • memory_limit 12M 12M

  • post_max_size 10M 10M
  • post_max_size 10M 10M

  • safe_mode Off Off
  • safe_mode关闭

  • upload_max_filesize 10M 10M
  • upload_max_filesize 10M 10M

  • upload_tmp_dir no value no value
  • upload_tmp_dir没有值没有值

4 个解决方案

#1


Make sure you have error reporting activated in php.ini: display_errors = On; this might give you a clue about what's going on. Production servers usually (should) have error reporting disabled.

确保在php.ini中激活了错误报告:display_errors = On;这可能会让你知道发生了什么。生产服务器通常(应该)禁用错误报告。

I recently had a similar problem, and increasing the memory_limit setting worked for me. If you read files content into variables, each variable will take about as much memory as the file size, increasing the scripts memory requirements.

我最近遇到了类似的问题,并且增加memory_limit设置对我有用。如果将文件内容读入变量,则每个变量将占用与文件大小相同的内存,从而增加了脚本内存要求。

#2


Where are those settings? If you're using .htaccess then your Apache configuration might not be allowing you to override those settings.

那些设置在哪里?如果您正在使用.htaccess,那么您的Apache配置可能不允许您覆盖这些设置。

I'd suggest checking with a phpinfo() call if those settings are indeed being applied or not:

如果确实应用了这些设置,我建议使用phpinfo()调用进行检查:

<?php
  phpinfo();
?>

#3


If it's a shared host, your host might have set a limit to override yours.

如果它是共享主机,则您的主机可能已设置限制以覆盖您的主机。

Otherwise, try making the POST limit higher than the file upload size. AFAIK, uploads are POSTED.

否则,请尝试将POST限制高于文件上载大小。 AFAIK,上传已发布。

#4


If the problem is due to the Host overriding your timeout, you can look for a host that still uses Apache 1: In Apache 1 the local .htaccess overrides the global setting even for the timeout.

如果问题是由于主机覆盖超时,您可以查找仍使用Apache 1的主机:在Apache 1中,本地.htaccess会覆盖全局设置,即使超时也是如此。

Otherwise, there are dozens of Java applett uploaders available for just a few dollars (Google it). They split the file, upload the parts and put the parts back together transparently.

否则,有几十个Java applett上传器只需几美元(谷歌它)。他们拆分文件,上传部件并将部件透明地放回原处。

This is a guaranteed fix for timeout, and has the added advantage of letting users pause and resume their upload, see the progress, et all.

这是一个有保证的超时修复,并且具有让用户暂停和恢复上传,查看进度等所有优点。

(Flash based uploaders don't have this advantage.)

(基于Flash的上传者没有这个优势。)

#1


Make sure you have error reporting activated in php.ini: display_errors = On; this might give you a clue about what's going on. Production servers usually (should) have error reporting disabled.

确保在php.ini中激活了错误报告:display_errors = On;这可能会让你知道发生了什么。生产服务器通常(应该)禁用错误报告。

I recently had a similar problem, and increasing the memory_limit setting worked for me. If you read files content into variables, each variable will take about as much memory as the file size, increasing the scripts memory requirements.

我最近遇到了类似的问题,并且增加memory_limit设置对我有用。如果将文件内容读入变量,则每个变量将占用与文件大小相同的内存,从而增加了脚本内存要求。

#2


Where are those settings? If you're using .htaccess then your Apache configuration might not be allowing you to override those settings.

那些设置在哪里?如果您正在使用.htaccess,那么您的Apache配置可能不允许您覆盖这些设置。

I'd suggest checking with a phpinfo() call if those settings are indeed being applied or not:

如果确实应用了这些设置,我建议使用phpinfo()调用进行检查:

<?php
  phpinfo();
?>

#3


If it's a shared host, your host might have set a limit to override yours.

如果它是共享主机,则您的主机可能已设置限制以覆盖您的主机。

Otherwise, try making the POST limit higher than the file upload size. AFAIK, uploads are POSTED.

否则,请尝试将POST限制高于文件上载大小。 AFAIK,上传已发布。

#4


If the problem is due to the Host overriding your timeout, you can look for a host that still uses Apache 1: In Apache 1 the local .htaccess overrides the global setting even for the timeout.

如果问题是由于主机覆盖超时,您可以查找仍使用Apache 1的主机:在Apache 1中,本地.htaccess会覆盖全局设置,即使超时也是如此。

Otherwise, there are dozens of Java applett uploaders available for just a few dollars (Google it). They split the file, upload the parts and put the parts back together transparently.

否则,有几十个Java applett上传器只需几美元(谷歌它)。他们拆分文件,上传部件并将部件透明地放回原处。

This is a guaranteed fix for timeout, and has the added advantage of letting users pause and resume their upload, see the progress, et all.

这是一个有保证的超时修复,并且具有让用户暂停和恢复上传,查看进度等所有优点。

(Flash based uploaders don't have this advantage.)

(基于Flash的上传者没有这个优势。)