How To Increase Maximum Upload File Size In PHP

PHP is a server-side scripting language that runs on Apache/Nginx server. By default, your configured server has a specific limit on the file size. Sometimes, you need to change this limit of file size. In this article, we study how to increase the maximum upload file size in PHP.

Why Need To Change File Upload Size Limit?

Let’s say your server allows you to upload file size up to 2MB. Now, when you try to upload a file with a size greater than 2MB then the server throws the error something like below.

file exceeds the maximum size allowed

This error indicates your server does not allow you to upload the file which is greater than 2MB in size. But what if you want to upload a large file that is bigger than 2MB?

There are 2 ways you can change this file size limit. One is through .htaccess and the other is using php.ini file.

Increase Maximum Upload File Size using htaccess Method

You may find the .htaccess file in the root directory. If it is not there then create it. To change the limit of file size, open the .htaccess file in your editor and add the below lines in it.

php_value upload_max_filesize 30M
php_value post_max_size 30M

In the above code, I passed value 30M which will allow you to upload a file with size up to 30MB. Change this value as per your requirement.

Note: Some servers may not take effect if you change file size limit using .htaccess file. If this option is not working for your server, then you can do this using php.ini file which describes below.

Increase Upload File Size Limit using PHP.INI

php.ini is the default configuration file which require to run your PHP applications. This file used to control extensions, upload size, file timeouts, resources limit, etc.

In order to increase file size limit, you need to edit values for post_max_size, upload_max_filesize in the php.ini file.

post_max_size = 30M
upload_max_filesize = 30M

Here also I passed the value 30M. You can put any value as per your requirement. These values apply globally which means all your PHP applications will have this configured value.

Next restart the server. And now you can upload the file with the size up to 30MB.

Related Articles

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

1 thought on “How To Increase Maximum Upload File Size In PHP

Leave a Reply

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