How to Increase the File Upload Size with PHP
Here, we will assist you in finding the best way to increase the file upload size with the help of PHP arsenal. Read it carefully and follow the examples.
Almost every PHP developer is in search of a means to increase the file upload size with PHP.
Follow this snippet to learn how to increase the file upload size accurately. The PHP file upload size is set to 2MB by default. Luckily, the php.ini configuration file allows increasing it easily.
To increase the upload size of the file, you should change the following variables inside your <kbd class="highlighted">php.ini</kbd> file: <kbd class="highlighted">upload_max_filesize</kbd> and <kbd class="highlighted">post_max_size</kbd>. Here is how to do that:
increase upload file size php
upload_max_filesize = 12M
post_max_size = 13MAlso, you have the option of setting the maximum number of files that can be uploaded at a time with the help of <kbd class="highlighted">max_file_uploads</kbd> like this:
increase upload file size php
max_file_uploads = 27It is essential to know that since PHP 5.3.4, each upload field that is left blank on submission will not be counted towards the limit.
The <kbd class="highlighted">post_max_size</kbd> variable is used to set the maximum size of POST data that PHP will accept. After setting a value of 0, the limit is disabled. In case POST data reading is disabled with <kbd class="highlighted">enable_post_data_reading</kbd>, it will be ignored.
After making the modification above, it is required to save the php.ini file and restart the web server. For restarting the web server, you should follow the commands below:
restart web server php
# SystemD
systemctl restart nginx
systemctl restart httpd
systemctl restart apache2
# Sys Vinit
service nginx restart
service httpd restart
service apache2 restartIn this tutorial, we covered one of the most common issues in PHP. Now, you can easily increase the size of the upload file in PHP. So, it will help you not to worry about size limits anymore. You can verify the changes by checking phpinfo() or running php -i.