This is a short guide on how to increase PHP’s maximum upload size. Note that this will require the ability to edit certain PHP directives, which might not be the case if your app is running on a restrictive shared hosting plan.
Modify the php.ini file.
The best way to modify the maximum upload values is to edit your php.ini file. There are two directives in the php.ini file that you will need to change. These are:
- upload_max_filesize: This is the maximum size of an uploaded file. The default value for this is currently 2MB.
- post_max_size: This is the maximum size that a POST request can be. Note that this value must be larger than the value specified for upload_max_filesize. The default value for this directive is 8MB.
Let’s say, for example, that we want our maximum upload size to be 64MB. Well, in this case, we can use the following values:
post_max_size = 66M upload_max_filesize = 64M
Note that I intentionally set the post_max_size directive to 66MB. This is because the uploaded file will be a part of the overall POST request and it is likely that we will need some extra space for other form data.
Be sure to restart your web server and PHP for the changes to take effect!
Changing the maximum upload size with ini_set.
Newer versions of PHP will not allow you to modify these values via the ini_set function. This is because the two directives involved are PHP_INI_PERDIR. This has been the case since PHP version 5.3.
Using the .user.ini file.
If you do not have access to the php.ini file, then you can try creating a .user.ini file and placing it in the same directory as your upload script. This can work because directives under PHP_INI_PERDIR mode can be changed via a php.ini, a .htaccess or a .user.ini file. Note that this type of configuration file can only be used with PHP version 5.3 and above.
If I wanted to set the max upload file size to 100MB, I could create a .user.ini file with the following two lines in it:
post_max_size = 102M upload_max_filesize = 100M
Once again, I made sure that post_max_size was larger than upload_max_filesize.
Using the .htaccess file.
If your host allows you to override PHP values using a .htaccess file, then you can use something like this:
<IfModule mod_php5.c> php_value upload_max_filesize 64M php_value post_max_size 66M </IfModule>
Note that you will need to change mod_php5.c to mod_php7.c if you are using PHP 7.
If none of the above solutions work, then you may need to contact your web host and seek clarification on what their max upload file size value is and whether or not you can change it.