The maximum allowed size for file uploads in PHP are defined by the upload_max_filesize directive. As file uploads are normally done using HTTP POST method, it is also limited by the post_max_size value.

post_max_size
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

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

This means the actual maximum upload file size for PHP is bound to the lowest value of both post_max_size and upload_max_filesize.

You increase the maximum upload file size for your PHP applications by updating your PHP configuration file for these two directives to the values that fit your requirement and then restart your web server.

Steps to increase upload file size for PHP application:

  1. Open php.ini file using your preferred text editor.
    $ sudo vi /etc/php/7.4/apache2/php.ini
  2. Search for upload_max_filesize directive.
    ; Maximum allowed size for uploaded files.
    ; http://php.net/upload-max-filesize
    upload_max_filesize = 2M
  3. Set your preferred value for upload_max_filesize.
    upload_max_filesize = 128M
  4. Search for post_max_size directive.
    ; 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 = 8M
  5. Set your preferred value for post_max_size.
    post_max_size = 128M

    This value should be set at least as high as upload_max_filesize value. Set the value to 0 to impose no limit on the size.

  6. Restart your web server for the changes to take effect

    Alternatively, you can add the following lines in your .htaccess and the setting will apply to scripts from within the .htaccess' directory without having to mess with PHP's configuration.

    php_value upload_max_filesize 128M
    php_value post_max_size 128M
Discuss the article:

Comment anonymously. Login not required.

Share!