Increase file size and number of uploads limits in PHP

Increase file size and number of uploads limits in PHP

Here I will cover two approaches to increase file size and number of uploads limits in PHP:

  1. using the .htaccess file
  2. using the php.ini

Why you should use .htaccess file

As always, I recommend utilizing the. htaccess file because the directives will remain the same regardless of whatever PHP version you use, unlike with .ini files where you have to modify the ini file for each new PHP version you use.

  • The php.ini file is a global configuration file. If the server has numerous sites running the same PHP version, any changes we make to the php.ini file will affect all of them.
  • Also, after a PHP upgrade, the php.ini file may be lost. Each upgrade to a non-minor PHP version will have its own php.ini file, and our previous settings will be lost.
  • There’s a good chance that none of these options are included in any source control. Normally, we would push our web application code to a git repository, but because the php.ini file is not part of the program, but rather part of the host environment, it would not be included. These settings will be missing from all further checkouts of that repo.

What is what

upload_max_filesizecontrols the maximum size of each file
max_file_uploadsmax number of files that can be uploaded at a time
post_max_sizemax size of POST data that PHP will accept
memory_limitmax amount of memory a script may consume
max_execution_timemax execution time of each script, in seconds
max_input_timemax amount of time each script may spend parsing request data

Increase file size and number of uploads limits in PHP using .htaccess

Inside the .htaccess file simply add the directives:

php_value upload_max_filesize 20M
php_value max_file_uploads 50
php_value post_max_size 800M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 180

Save the file and check in your info.php file if the changes are effective. Local values of the above settings (local to the site) have changed as set above, while the master values have remained unchanged.

image 73 - Increase file size and number of uploads limits in PHP

We don’t need to restart Apache because we’re updating the values during runtime in the .htaccess file.


Increase file size and number of uploads limits in PHP using php.ini

First we need to locate the php.ini file, we can create a new info.php file and note the location of the file:

image 74 - Increase file size and number of uploads limits in PHP

then open the file in editor:

nano /opt/alt/php73/etc/php.ini

add/edit the following values:

upload_max_filesize = 100M
max_file_uploads = 50
post_max_size = 256M
memory_limit = 256M

Once the changes to the php.ini file are made, you need to restart Apache:

sudo service httpd restart

Increase file size and number of uploads limits using MultiPHP INI Editor in cPanel

cPanel has a MultiPHP INI editor function that allows users to change PHP directives for their websites.

From cPanel:

image 76 - Increase file size and number of uploads limits in PHP

If you have access to the WHM panel then you can also set the directives for the PHP version, which will affect all websites that use that PHP version.

From WHM:

image 75 - Increase file size and number of uploads limits in PHP

Increase file size and number of uploads limits using PHP ini_set() function

PHP <5.3 has a init_set() function by which you can set the upload_max_filesize and post_max_size value

ini_set('upload_max_filesize', '200M');
ini_set('post_max_size', '256M');
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.