Php ini file upload

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.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Php ini file upload

We are thankful for your never ending support.

How to change the maximum upload file size for PHP scripts

This article describes how to change the maximum upload file size for PHP scripts by using the upload_max_filesize and post_max_size php directives. 

Changing the maximum upload file size

By default, the maximum upload file size for PHP scripts is set to 128 megabytes. However, you may want to change these limits. For example, you can set a lower limit to prevent users from uploading large files to your site. To do this, change the upload_max_filesize and post_max_size directives.

To ensure that file uploads work correctly, the post_max_size directive should be a little larger than the upload_max_filesize. For example, the following settings demonstrate how to set a file upload limit to 20 megabytes:

upload_max_filesize = 20M
post_max_size = 21M

To verify the current value of the upload_max_filesize directive and other directives, you can use the phpinfo() function. For more information, please see this article.

Setting the directives

The preferred way to set php directives is using the graphical tools in the control panel.

For accounts using the cPanel control panel, see this article.

For accounts using the Plesk control panel, see this article.

Many accounts also allow the use of a custom php.ini file.  For instructions to create a custom php.ini file, see this article.

More Information

  • To view a complete list of php.ini directives, please visit http://www.php.net/manual/en/ini.list.php.
  • For more information about the upload_max_filesize directive, please visit http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize.
  • For more information about the post_max_size directive, please visit http://www.php.net/manual/en/ini.core.php#ini.post-max-size.

Where do I upload PHP ini file?

PHP File Upload.
Configure The "php.ini" File. First, ensure that PHP is configured to allow file uploads. ... .
Check if File Already Exists. Now we can add some restrictions. ... .
Limit File Size. The file input field in our HTML form above is named "fileToUpload". ... .
Limit File Type. ... .
Complete Upload File PHP Script..

How can I change upload file size in PHP ini?

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. 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 .

What is the max upload file size in PHP?

The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.

Can we upload a file of any size to a PHP application?

By default, PHP permits a maximum file upload of 2MB. You can ask users to resize their images before uploading but let's face it: they won't. Fortunately, we can increase the limit when necessary. Two PHP configuration options control the maximum upload size: upload_max_filesize and post_max_size .