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:
<?php // here start your php file ob_get_contents(); ob_end_clean();
That is. After …
if($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0) { echo "Your file exceeds allowed upload file dimension"; }
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:
$out = ob_get_contents(); $out = str_replace(array("\n", "\r", "\t", " "), "", $input); ob_end_clean();
Answered How to prevent Warning: POST Content-Length at: stackoverflow.com