In PHP, the size of files you can upload is controlled by the upload_max_filesize directive. This value sets the maximum allowed file size for uploads via the HTTP POST method. However, the actual limit is also affected by the post_max_size directive, which restricts the total size of post data.
post_max_size
Maximum size of POST data that PHP will accept.
Its value may be 0 to disable the limit.
It is ignored if POST data reading is disabled through enable_post_data_reading.
http://php.net/post-max-size
upload_max_filesize
Maximum allowed size for uploaded files.
http://php.net/upload-max-filesize
To enable larger file uploads, both the upload_max_filesize and post_max_size values need to be increased. The upload limit will always be determined by the lower of these two settings. Proper configuration is essential to avoid issues like failed uploads due to size limitations.
For users without administrative access, these settings can be adjusted in the .htaccess file. This allows control over upload limits even when direct access to the PHP configuration is not available.
Steps to increase maximum upload size for PHP application:
- Open php.ini file using your preferred text editor.
$ sudo vi /etc/php/7.4/apache2/php.ini
Related: PHP configuration files
- Find the post_max_size directive.
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 2M
- Set your preferred value for upload_max_filesize.
upload_max_filesize = 128M
- Search for post_max_size directive.
; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 8M
- Set the desired value for post_max_size.
post_max_size = 128M
This value should be set at least as high as upload_max_filesize value. Set the value to 0 to impose no limit on the size.
- Restart the web server to apply the changes.
Alternatively, you can add the following lines in your .htaccess and the setting will apply to scripts from within the .htaccess directory without having to mess with PHP's configuration.
php_value upload_max_filesize 128M php_value post_max_size 128M
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.