How To Change The Maximum Upload File Size in PHP

This quick php tutorial help to solve upload_max_filesize issue, There are number of ways to solve max upload file size issue.We will discuss in this tutorial one by one option to increase file upload size.

The File upload is very common functionality for web application.The file can be word, excel, csv or pdf. I have shared tutorial PHP Image Upload Using jQuery and MySQL

and Read File Line By Line Using PHP.

As We know, PHP default file size is 2MB to upload file into server, if you are trying to upload file which size is more than 2MB then You will get error, The error would be fatal error like “the uploaded file exceeds the upload_max_filesize“.

PHP are providing different options to increase max size upload limit.The Upload file size Limit can be increase through .htaccess,php_ini() function or php.ini file.

Uploaded file exceeds the upload_max_filesize Using php.ini

The php.ini file location depends on php web development tool(WAMP/XAMP/) and operating system(Ubuntu/Centos).You can find it ‘XAMPP\php’ into windows and etc/ folder into Linux.Now open php.ini file and search upload_max_filesize and post_max_size.

You can also find php.ini file location using below command, This command will work only for Linux machine:
php -i | grep -i "loaded configuration file"

The php.ini file will contain below entry:

The post_max_size value is greater than or equal to upload_max_filesize value.There is one more configuration parameter to handle number of file upload at once, The max_file_uploads is use to control number of file upload at once using form upload.


Now we will change 2M to any other value whatever you want to fix max upload file size.I am increasing upload_max_filesize value from 2 to 4 then, The value would be:

Save the file and restart Apache/Nginx server.

Uploaded file exceeds the upload_max_filesize Using PHP Code

Sometimes, We do not have right to edit php.ini file, So what will happen if you want to upload file more than 2MB, The PHP providing one another solution to handle upload_max_filesize. PHP have configuration method to set php.ini parameter.

Set MAX upload file size using php_ini() Method

The PHP have ini_set function to increase max file upload size limit but its work only for PHP version below 5.3:

The Above code can used in any php file where do you want to upload, For global application configuration, You can define into main application configuration file(app.php/config.php).

Increase Uploaded File Exceeds

The php version greater than 5.3 need to use PHP_INI_PERDIR method. You can get more information from Where a configuration setting may be set.

Uploaded File Size Limit Using .htaccess

You can handle max file upload file size limit from .htaccess file as well. The .htaccess is use to handle application level configurations.

Sometimes, Above code will through Internal server error, Then You can put configurations in IfModule tag.

If you are using php 7:

Uploaded File Size Limit Using .user.ini

The .user.ini file use to handle php configuration parameters on shared server.We will made below entry into .user.ini file.

How To handle File Upload Max Size in WordPress

The WordPress is very popular PHP cms, The wordpress have the wp-config.php file for application level configuration.We can handle the uploaded file exceeds the upload_max_filesize directive in php.ini error is by editing the wp-config.php file. It is located in your main WordPress directory.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.