How to solve the error upload_max_filesize in PHP

If you own a website where users are allowed to upload files, you might often get complaints stating that they are unable to upload files. They would be hitting an error as follows:

“Error: The uploaded file exceeds the upload_max_filesize directive in php.ini”

upload_max_filesize mentioned in the error above is the limit of the size of a file that can be uploaded to the server. The default value is normally 2M in all servers, and when someone tries to upload a file greater than 2M this error is obtained.

How to solve the error upload_max_filesize

Users can change the value of upload_max_filesize from their cPanel itself and this post describes how to do that. First, log in to your cPanel account using the cPanel login details.

 

php1

Once you are in the dashboard, go to Software -> Select PHP Version. It will take you to a page where you can select the PHP version and other PHP extensions. To the top right, you will notice an option ‘Switch to PHP Options’.

 

php6

Click on that option and you will find a list of PHP options that you can configure. To the bottom of the list, you will find upload_max_filesize. To its right, there is a drop down box with various sizes to choose from. Choose the value you require and hit ‘Apply’. Beneath it is a ‘Save’ button, click on it.

 

upload_max_filesize

For example, I choose 64M.  Before confirming the changes, you also need to consider the option ‘post_max_size’. If the size of the total upload exceeds the default 8M, it will again hit an error. Hence, it is advisable to raise the value of post_max_size also on the same page.

Now, let us confirm the changes we made by uploading a phpinfo page. Create a file, say for example info.php with the following contents and upload it to the public_html folder of your domain.

<?php

phpinfo();

?>

My domain is copablog.com and now I can access the file in a browser as http://copablog.com/info.php. Search for upload_max_filesize and check the value. I can see that it has changed to 64M.

upload_max_filesize

Now try uploading the file again and you will be able to upload it successfully !!!

Was this helpful?

Thanks for your feedback!

Gustavo Bastos

Leave a Reply

Your email address will not be published. Required fields are marked *