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

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

问题描述

目前,当用户上传一张照片时,页面显示Warning:POST内容长度 XXX 字节超过了在第0行的未知的21000000字节的限制。



我知道这意味着什么,我不是寻找解决方案,如增加max_upload值,甚至memory_size_limit ...因为用户可能和用户上传TB的废话甚至如果您明确告诉他们只有最多20MB的文件,只允许图片。

我正在寻找一个解决方案:


  • 如何防止此警告发生?

    或至少:
  • 如何防止显示此警告?



编辑:请读! - 请理解当然是在处理(自第1行以后)错误/警告,问题是发生在虚拟第0行上,这就是为什么我需要隐藏错误或阻止错误发生 - 因为我不能在发生错误的地方放置任何代码。



EDIT2:最后,经过很长时间的研究和挖掘,我得到了一个想法 - 它的工作 - 看到我自己的答案。因此,经过搜索,而不是今天的工作,我终于有了一个想法如何解决这个问题,它的工作,甚至没有造成太大的损害。但是在做之前,请先了解你在做什么。 :)正如我在我的一个评论中提出的,它真的可以关闭.htacess中的PHP错误 - 只是关闭PHP的启动警告。



在应用解决方案:



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



另请注意:在线0上的启动错误比这个更多。 / p>

之前做:在做这个之前,您应该准备好您的脚本,它应该检查上传的内容大小并给用户一个正确的信息消息。警告不显示不是意味着你不应该对此做任何事情。这意味着EXACT oposite - 你应该尽一切可能使事情至少接近警告提升 - 检查,仔细检查是否可以,处理错误并提出自己的错误信息。

添加到您的.htaccess中:



php_flag display_startup_errors off



这不是那么邪恶,因为它似乎是:



请注意,这将关闭启动错误

因此所有常规的PHP错误/警告/通知都保持ON:)甚至XAMPP的PHP本身建议它用于生产:
$ b $ php.ini 文件literaly说:

 ; display_startup_errors 
;默认值:关
;发展价值:关于
;生产值:关

PS:启动错误似乎是那​​些错误之前 PHP脚本自己执行 - 这些错误通常是试图说服你他们在线0



感谢我的想法和这个答案:



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

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".

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.

I am looking for a solution on:

  • How to prevent this warning(s) to even happen?
    OR at least:
  • How to prevent displaying of this warning(s)?

EDIT: 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.

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

解决方案

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.

Before you apply the solution:

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

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.

Add this to your .htaccess:

php_flag display_startup_errors off

It is not that evil as it seems to be:

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

Even XAMPP's PHP "itself" recommends it for production:

The php.ini file literaly says:

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

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.

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

EDIT: 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内容 - 长度和内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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