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:
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.
Post-Content-Length Exceeds The Limit error you are getting because your upload size of the theme is more than the set file-max upload file size in php.ini You may also be interested in Fomo Plugins, Email marketing Service and Page Builder Tool
PHP Warning: POST Content-Length of 77870742 bytes exceeds the limit of 8388608 bytes. The error message above will occur if the size of a POST request exceeds the limit that has been set in the post_max_size directive in your php.ini file.
a note to passersby: this error and fix is not specific to WordPress or XAMPP. It is applicable generally to the PHP error POST Content-Length of X bytes exceeds the limit of Y 8388608 bytes is 8M, the default limit in PHP. Update your post_max_size in php.ini to a larger value.
The size limit for a POST request has been set to 8MB. However, the size of our POST request is 77.87MB. As you can see, it is well over the allowed limit.
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.
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.
php_flag display_startup_errors off
Please note that this turns off startup errors only.
So all the regular PHP errors/warnings/notices stays ON :)
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 :)
The question is
How to prevent Warning: POST Content-Length
the answer is, without edit any config value, put this code at the very start of the file that will receive the form to be processed:
<?php // here start your php file
ob_get_contents();
ob_end_clean();
That is. No more warning, as well anything else you do not want as output on your page. After, as suggested elsewhere you can decide what to do with:
if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0){ echo"WoW your file is too big!"; }
Maybe also chunk the file, if in another way you pass correct values about file to be processed by Php.
as explained here Warning: POST Content-Lenght ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With