In the last days, a friend of mine asked for help in a very old project that uses PHP 5.4, so I had to install a compatible version of xampp for that version of PHP. I configured the php.ini
file really fast because I wanted to work on other stuff, however I committed a newbie mistake as I adjusted just a single parameter in the php.ini file that should allow me to import bigger SQL files directly in the browser.
In this article, I will explain you why this exception occurs and how to solve it in your local environment of XAMPP.
How to trigger this exception
If you decide to modify the post_max_size and upload_max_filesize properties of the configuration file of PHP, you need to be careful, because, if you decide to assign a greater value to upload_max_filesize
than the allowed size for post_max_size
, the exception will be triggered. For example, if you set 2MB
to the allowed post max size and 8MB
to the max upload filesize like this in your php.ini
file:
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size=2M
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=8M
If you try to upload a database to import through PHPMyAdmin, the exception will be thrown.
How to prevent or solve this exception
Be sure to set equal values to the mentioned properties post_max_size
and upload_max_filesize
. It's just logic, as if you configure a value of these properties greater than the other one, it simply won't work, for example, you cannot upload a file of 5MB if your max allowed filesize is of 8MB (theoretically the filesize passes), but the max allowed POST size is of only 2M, it just doesn't make sense. Fix the values to use the same number and that should be enough (the value can be whatever you need to, not specifically 64MB):
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size=64M
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=64M
Happy coding ❤️!