Prevent Warning: POST Content-Length of bytes exceeds the limit – how to fix smartly

When a form multipart/form-data is submitted to send a file, if dimension of submitted file on form to be uploaded, exceeds the dimension of MAX_FILE_SIZE value,  PHP emit a warning and the $_FILES global is empty.

Warning: POST Content-Length of …. bytes exceeds the limit

In WordPress you have something like:

Warning: POST Content-Length of ….. bytes exceeds the limit of … bytes in Unknown on line 0

To resolve the problem about if dimension of submitted file to upload exceeds the dimension of MAX_FILE_SIZE value (Php emit a Warning)  server side, there is no pre javascript check needed, no ini_set value to change (if not needed), the php warning (as anything else you do not want emitted by the browser before you do not want really it) can be removed from output with the follow Php code, that need to be placed at the very start of the Php file you call (that will receive the empty $_FILES input and that so will emit the Php warning).

The code is just this:

That is.  After …

manage what to do. You could also use Javascript to detect and process the file. Maybe chunk it and enqueue for the upload.

This i had use to resolve an old bug in WP about RSS, that was not well parsed by browsers as the output was containing spaces before the code to be interpreted. The solution was +- the same:

Answered How to prevent Warning: POST Content-Length at: stackoverflow.com