如何防止警告:POST Content-Length 和内存大小 [英] How to prevent Warning: POST Content-Length and memory size

查看:29
本文介绍了如何防止警告:POST Content-Length 和内存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,当用户上传照片时,页面会显示警告:XXX 字节的 POST Content-Length 超出第 0 行未知中 21000000 字节的限制".

Currently when user uploads a photo the page says "Warning: POST Content-Length of XXX bytes exceeds the limit of 21000000 bytes in Unknown on line 0".

我知道这意味着什么,我不是在寻找诸如增加 max_upload 值甚至 memory_size_limit 之类的解决方案...因为即使您明确告诉用户,用户也可能上传 TB 级的废话他们只允许最大 20MB 的文件,并且只允许图像.

I know what that means and I am NOT looking for the solultions like the increasing the max_upload values or even memory_size_limit... Because users may and users will upload terabytes of nonsense even if you explicitly tell them only max 20MB files and only images are allowed.

我正在寻找解决方案:

  • 如何防止这种警告发生?
    或者至少:
  • 如何防止显示此警告?

请阅读!- 请理解当然我正在处理错误/警告(从第 1 行开始),问题是这发生在虚拟的第 0 行",这就是我需要的原因隐藏错误或防止它引发 - 因为我不能在发生错误的地方之前放置任何代码.

PLEASE READ ! - Please understand that of course I am handling the error/warning after (since line 1) , problem is this happens on a virtual "line 0" that is why I need to hide the error or prevent it to raise - because I cant put any code before the place where the error happens.

经过长时间的研究和挖掘,我终于有了一个想法——它奏效了——看看我自己的答案.

Finally after a very long research and digging I got an idea - it worked - see my own answer.

推荐答案

所以在今天搜索而不是工作之后,我终于想到了如何解决这个问题,它有效,甚至没有造成太大损害.但是请先了解您在做什么,然后再做.:) 正如我在我的一条评论中所建议的,确实可以关闭 .htacess 中的 PHP 错误 - 只需关闭 PHP 启动警告即可.

So after searching instead of working today I finally got an idea how to solve this, it worked, and even didnt cause much damage. But please first understand what you are doing, before doing it. :) As I suggested in one of my comments it is really possible to turn off PHP errors in .htacess - just turn off the PHP startup warnings.

请注意:将此代码插入到 .htaccess 后,您将看不到任何启动错误

Note that: after you insert this code to your .htaccess you won't be able to see any startup error

另请注意:0"行的启动错误比这多.

Also note that: there are more start up errors on line "0" than this one.

之前执行:在执行此操作之前,您应该准备脚本,以便检查上传的内容大小并向用户提供适当的信息消息.警告没有显示这一事实意味着您不应该对此采取任何措施.这意味着完全相反 - 您应该尽一切努力使某些事情至少接近警告引发 - 检查,如果可以,请仔细检查,处理错误并提出您自己的错误消息.

Do before: Before you do this you should prepare your script in the way that it should check the uploaded content size and give user a proper information message. The fact that the warning doesnt show DOES NOT mean that you should do nothing about it. It means the EXACT oposite - you should do all that you can to make something at least near-equal to the warning raise - check, double check if you can, handle error and raise your own error message.

php_flag display_startup_errors off

请注意,这会关闭启动错误.
所以所有常规的 PHP 错误/警告/通知都保持开启 :)

Please note that this turns off startup errors only.
So all the regular PHP errors/warnings/notices stays ON :)

php.ini 文件字面意思是:

; display_startup_errors
;   Default Value: Off
;   Development Value: On
;   Production Value: Off

PS:启动错误"似乎是在 PHP 脚本自身执行之前的那些错误 - 这些错误通常试图说服"您他们位于 0 行.

PS: "startup error" seems to be those errors before PHP script is executed itself - these errors are usually trying to "persuade" you that they are on the line 0.

感谢我的想法和这个答案:如何在 .htaccess 文件中禁用 PHP 中的通知和警告?

Thanks to my idea and this answer: How to disable notice and warning in PHP within .htaccess file?

由于这是一个 php_flag 设置,如果您有 PHP 的自定义安装,您当然也可以在 php.ini 中默认设置它:)

As this is a php_flag setting, you can of course also set it by default in your php.ini if you have custom instalation of PHP :)

这篇关于如何防止警告:POST Content-Length 和内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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