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 recommend do not increase this value too high on shared servers. The tutorial will help you to change upload max filesize limit in PHP.
You may like:
- How to Install PHP7 on Ubuntu, LinuxMint
- How to Install PHP7 on CentOS, Red Hat
- How to Install PHP7 on Debian
- How to Install PHP7 on macOS
The first you need to find the loaded PHP configuration file (php.ini) on your system. For PHP CLI execute below command to find 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 used php.ini file.
Change Upload Max Filesize Limit
The upload_max_filesize variable defines the maximum size of a file can be uploaded. The post_max_size variable defined the maximum size of data can be posted at a time. So you need to set both upload_max_filesize and post_max_size variable to change upload max filesize in PHP. Edit the php.ini file increase maximum allowed upload file size edit PHP configuration file “php.ini” and increase the size of following value.
; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesizeupload_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-sizepost_max_size = 20M
Save the configuration file and restart the web server to reload the changes.
Set Max File Uploads in PHP
Also, set the maximum number of files that can be uploaded with a single request set max_file_uploads directive.
; Maximum number of files that can be uploaded via a single requestmax_file_uploads = 20
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-uploadsfile_uploads = Off