How to Increase Maximum Upload file Size in PHP

Channel: Linux
Abstract: The upload_max_filesize and post_max_size directives determines the maximum file size will be allowed by PHP to upload on server. Default this value i

The upload_max_filesize and post_max_size directives determines the maximum file size will be allowed by PHP to upload on server. Default this value is set to 2M, You can increase this value as per your application requirements.

We never recommend you increase this value too high on a production server. The tutorial will help you to change the upload max file size limit in PHP.

You may like:

  • How to Install PHP 7 on Ubuntu, LinuxMint
  • How to Install PHP 7 on CentOS, Red Hat
  • How to Install PHP 7 on Debian
  • How to Install PHP 7 on macOS
1. Locate correct php.ini

First, you need to find the loaded PHP configuration file (php.ini) on your system. For PHP CLI execute the below command to find the php.ini file.

php -i | grep php.ini 

For the web server like Apache/Nginx, create a PHP script with phpinfo() function and access in a web browser. This will show you the location of the used php.ini file.

2. Change upload_max_filesize Value

The upload_max_filesize variable defines the maximum size of a file that can be uploaded. The post_max_size variable defined the maximum size of data that can be posted at a time. So you need to set both upload_max_filesize and post_max_size variables to change upload max filesize in PHP.

Edit the php.ini file to increase the maximum allowed upload file size edit the PHP configuration file "php.ini" and increase the size of the following value.

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize 

upload_max_filesize = 20M
  
; 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 = 20M

Save the configuration file and restart the webserver to reload the changes.

3. Set max_file_uploads in PHP

Also, set the maximum number of files that can be uploaded with a single request and set the max_file_uploads directive.

; Maximum number of files that can be uploaded via a single request 

max_file_uploads = 20
4. Disable File Upload in PHP

If our application doesn't need to upload files, we can simply disable by setting Off to the file_uploads directive.

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads 

file_uploads = Off
Conclusion

In this tutorial, you have learned, how to change upload_max_filesize, and post_max_size directives in PHP configuration. Also, you can enable or disable file uploads on your server.

Ref From: tecadmin

Related articles