PHP 大文件上传错误 [英] Large File Upload Errors with PHP

查看:31
本文介绍了PHP 大文件上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传了一张幻灯片图片,用户不断上传超过 2MB 的文件.低于此大小的文件可以正常工作,但超过此大小的文件会导致浏览器超时.

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.

这是我的 php ini 设置:

Here are my php ini settings:

  • 最大内存分配:12M
  • 最大文件上传大小:10M
  • 最大 HTTP Post 大小:10M
  • 最大执行时间:60
  • 最大输入解析时间:120

这些设置在配置文件里面,我可以直接改.使用 phpinfo() 时会显示更改.

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

我在 apache 服务器和 php 4.3.9 上运行(客户端的选择,不是我的).apache 服务器的请求限制设置为默认值,我认为大约在 2GB 左右?

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?

当我使用 firebug 网络监视器时,我似乎没有收到服务器的完整响应,尽管我在使用此工具方面经验不足.事情似乎在 43 秒左右超时.

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.

我在网上能找到的所有帮助都指出上述设置是罪魁祸首,但所有这些设置都远高于这个 2MB 文件和 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.

有什么建议可以解决这个问题吗?

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

这里是来自 phpinfo() 的相关 php ini 设置.如果我需要再发帖,请告诉我.

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

  • file_uploads 开启
  • 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 关闭 关闭
  • upload_max_filesize 10M 10M
  • upload_tmp_dir 无值 无值

推荐答案

确保在 php.ini 中激活了错误报告:display_errors = On;这可能会为您提供有关正在发生的事情的线索.生产服务器通常(应该)禁用错误报告.

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.

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

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.

这篇关于PHP 大文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆