Php

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:

upload_max_filesize=2M
post_max_size=8M

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.

max_file_uploads=20

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:
upload_max_filesize=4M

Related Post

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:

ini_set('post_max_size', '4M');
ini_set('upload_max_filesize', '8M');

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.

php_value upload_max_filesize 4M
php_value post_max_size 8M

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


   php_value upload_max_filesize 4M
   php_value post_max_size 8M

If you are using php 7:


   php_value upload_max_filesize 4M
   php_value post_max_size 8M

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.

upload_max_filesize = 40M
post_max_size = 40M

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.

@ini_set('upload_max_size' , '4M' );
@ini_set('post_max_size' , '6M' );

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

3 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories