How to Increase the File Upload Size with PHP

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.

So, for increasing the upload size of the file, you should change the following variables inside your php.ini file: xupload_max_filesize and upload_max_filesize. Here is how to do that:

upload_max_filesize = 12M
post_max_size = 12M

Also, you have the option of setting the maximum number of files that can be uploaded at a time with the help of max_file_uploads like this:

max_file_uploads = 27

It 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 post_max_size variable is applied for setting the maximum size of POST data, which should be accepted by PHP. After setting a value of 0, the limit is disabled. In case POST data reading is disabled with enable_post_data_reading, 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:

--------------- SystemD --------------- 
# systemctl restart nginx
# systemctl restart httpd		
# systemctl restart apache2	

--------------- Sys Vinit ---------------
# service nginx restart
# service httpd restart		
# service apache2 restart

In this tutorial, we represented to you one of the most in-demand 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.


Do you find this helpful?

Related articles