How to Increase File Upload Size in PHP

Are you a PHP developer or a system administrator managing servers that host PHP applications? Are you looking for a way to increase or set file upload size in PHP? If yes, then follow this article that shows you how to increase file upload size in PHP and also will explain some of PHP’s core directives for handling file uploads as well as POST data.

By default, PHP file upload size is set to maximum 2MB file on the server, but you can increase or decrease the maximum size of file upload using the PHP configuration file (php.ini), this file can be found in different locations on different Linux distributions.

# vim /etc/php.ini                   [On Cent/RHEL/Fedora]
# vim /etc/php/7.0/apache2/php.ini   [On Debian/Ubuntu]

To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size variable’s in your php.ini file.

upload_max_filesize = 10M
post_max_size = 10M

In addition, you can also set the maximum number of files allowed to be uploaded simultaneously, in a single request, using the max_file_uploads. Note that from PHP 5.3.4 and laster versions, any upload fields left blank on submission do not count towards this limit.

max_file_uploads = 25

The variable post_max_size which is used to set the maximum size of POST data that PHP will accept. Setting a value of 0 disables the limit. If POST data reading is disabled via enable_post_data_reading, then it is ignored.

Once you have made the above changes, save the modified php.ini file and restart the web server using following commands on your respective Linux distributions.

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

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

Thats It! In this short article, we have explained how to increase the file upload size in PHP. If you know any other way or have any questions do share with us using our comment section below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

2 Comments

Leave a Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.