apache PHP 大文件上传错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/757111/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:30:02  来源:igfitidea点击:

Large File Upload Errors with PHP

phpapachefile-upload

提问by Mesidin

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
  • Max file upload size: 10M
  • Max HTTP Post size: 10M
  • Max execution time: 60
  • Max input parsing time: 120
  • 最大内存分配:12M
  • 最大文件上传大小:10M
  • 最大 HTTP Post 大小:10M
  • 最大执行时间:60
  • 最大输入解析时间: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
  • max_execution_time 60 60
  • max_input_nesting_level 64 64
  • max_input_time 120 120
  • memory_limit 12M 12M
  • post_max_size 10M 10M
  • safe_mode Off Off
  • upload_max_filesize 10M 10M
  • upload_tmp_dir no value no value
  • file_uploads 开启
  • 最大执行时间 60 60
  • max_input_nesting_level 64 64
  • 最大输入时间 120 120
  • 内存限制 12M 12M
  • post_max_size 10M 10M
  • safe_mode 关 关
  • 上传最大文件大小 10M 10M
  • upload_tmp_dir 无值 无值

采纳答案by Adi

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 contentinto variables, each variable will take about as much memory as the file size, increasing the scripts memory requirements.

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

回答by Seb

Where are those settings? If you're using .htaccessthen 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();
?>

回答by Macha

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,上传已发布。

回答by SamGoody

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 小程序上传器(Google it)。他们拆分文件,上传各个部分,然后透明地将各个部分重新组合在一起。

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 的上传器没有这个优势。)