What should we do to hide POST Content-Length warning in php?

I disable all errors in php code. Still, I get this : “Warning: POST Content-Length of 24000429 bytes exceeds the limit of 8388608 bytes in Unknown on line 0”. What should I do to completely hide this kind of warnings/notices ? I did error_reporting(0); but still I see this warning.

You could try these settings at the top of the form page:

<?php 
ini_set( 'html_error', 'false' );
ini_set( 'error_reporting', 'false' );
ini_set( 'display_startup_errors',  'false' );
error_reporting(0)

// 

Edit:
Also try:

ini_set( 'memory_limit, '999M' ); // just guessing the syntax 

The PHP Manual has more info’

https://secure.php.net/manual/en/ini.core.php#ini.memory-limit

I did all but nothing hides max post file size warning I changed max post and upload values manually in php.ini to 999M now it works. Is there a way to handle this error like if(“error-id”){ echo “myMessageToUser”; } Thanks for your interest.

Try this:

<?php 

 // ...
 // ...

try {
 ?> 

    <!-- form stuff starts here  -->
    <!-- form stuff ends here -->

<?php
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
   // echo '<pre>;'  print_r( $e );  echo '</pre>'; 
}

1 Like

Your form data exceeds the PHPs default POST max data size which is 8MB. Try changing post_max_size to a bigger value. See http://php.net/manual/en/ini.core.php#ini.post-max-size .

1 Like

In this case it is a Warning so try-catch block won’t help. It is possible to convert PHP errors and warnings to exceptions with custom error handler. I think…

2 Likes

Error messages can be found in $_FILES, see http://php.net/manual/en/features.file-upload.errors.php

As for not displaying the warnings on the webpage, setting display_errors to 0 in your php.ini should do the trick.

Also please use a realistic value for max_upload_size. Unless people are allowed to upload entire movies 999M is way too high :slight_smile:

I set it back to 8M and i set display_errors to 0. However, still I see this message! I really did not understood why I see the warning.

Did you restart php-fpm or Apache (depending on what you use to serve php) after changing php.ini? Changes will not be reflected until you do that.

Of course I did. There is a special problem with that I think. There says if post file size exceeds $_POST $_FILES $_GET super globals are going to be empty. However it shows the warning at line 0 and I do not have opportunity to check it. Even ajax.php is empty that shows the warning naturally. That is why, I think, I should set it max size unlimited (it is 0 for newer php versions 0 is not disabling it.). Then, check if file size. To prevent flooding I could set max execution time so that will neve able to flood it forever for single post.

Okay then you should probably set display_startup_errors to 0 as well.

I found the exact way and the reason why that keeps showing. If this warning happens php script even not executed. This is same for all file errors. We should use .htaccess file and limit file upload. I am going to limit the file amount too later. If this happens php part of server will not say anything but just prevent upload. So our script will executed and we will able to handle all errors.

Everything you can do in .htaccess you can also do in php.ini, the only difference being that php.ini is system wide whereas .htaccess is only for a single project.

1 Like

I removed .htaccess I used try{ } finally{ } instead of catch and I prevented warning. Catch itself is not working

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.