mahenda Posted April 6, 2021 Share Posted April 6, 2021 As we know , A post_max_size used to limit the size of posted data via POST method while the upload_max_filesize used to limit the size of file to be uploaded I assume. post_max_size = 8m upload_max_filesize = 2m When i limit the user to only upload 100kb file, i say <pre> if (!empty($_FILES["myfile"]["tmp_name"]) && ($_FILES["myfile"]["size"] > 100000)) { echo "the file is too large"; } </pre> This message occur even when the file is greater than 8 m The problem come when the file is greater than 10m the warning message for post content is on the page is Warning: POST Content-Length of 9767236 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 What i want? I want to create my own warning as an error ie <pre> if (post_max_size > 18388608)) { echo "the posted content exceed our server limit "; } </pre> NB: some developers says we have to adjust the post_max_size i.e 200M what if user upload the file with 210M, the warning message will come back again Warning: POST Content-Length of 9767236 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 In short i want to give a normal user a meaningful warning Quote Link to comment https://forums.phpfreaks.com/topic/312427-post_max_size-and-upload_max_filesize-how-to-control-them-in-a-php-page-not-a-php-ini-file/ Share on other sites More sharing options...
mac_gyver Posted April 6, 2021 Share Posted April 6, 2021 when you exceed the post_max_size setting, both the $_POST and $_FILES arrays are empty, so, logic trying to use those values won't have anything to test. your post method form processing code should first test if a post method form was submitted. you can then compare the content-length (see $_SERVER['CONTENT_LENGTH']) value (which is in bytes) with the post_max_size (see ini_get('post_max_size') ) setting (which used to be in whatever units the setting is in - bytes or K, M, G short-notation, which may now be (unconfirmed) always in bytes due to the addition of the new Warning message for this condition) to produce your own error message. when on a live/public server you should set php's display_errors setting to OFF and set log_errors to ON to cause php error messages, which would include that new Warning message, to be logged instead of displayed. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312427-post_max_size-and-upload_max_filesize-how-to-control-them-in-a-php-page-not-a-php-ini-file/#findComment-1585613 Share on other sites More sharing options...
mahenda Posted April 6, 2021 Author Share Posted April 6, 2021 thanks Quote Link to comment https://forums.phpfreaks.com/topic/312427-post_max_size-and-upload_max_filesize-how-to-control-them-in-a-php-page-not-a-php-ini-file/#findComment-1585617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.