Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How to Increase Maximum Upload file Size in PHP

    How to Increase Maximum Upload file Size in PHP

    RahulBy RahulFebruary 22, 20153 Mins ReadUpdated:June 27, 2022

    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.

    configuration filesize PHP phpini
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Enable Short Open Tag (short_open_tag) in PHP
    Next Article How to Remove File Extension (.php, .html) from URL using .htaccess

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:June 19, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 22.04

    Updated:June 28, 20225 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install and Use PHP Composer on Debian 11

    Updated:February 16, 20224 Mins Read

    5 Comments

    1. Mixhig on July 11, 2020 5:06 pm

      Thank you very much for the invitation :). Best wishes.
      PS: How are you? I am from France 🙂

      Reply
    2. itaAMERB on December 5, 2019 2:09 pm

      Ok. I use translate and will be good ok?

      Reply
    3. rarddok on October 23, 2019 3:32 pm

      hi 🙂 bross 🙂

      Reply
    4. Andres on April 21, 2019 6:24 pm

      For anyone that can read this, i found my php.ini working in another path, was
      /etc/php/7.0/cgi/php.ini

      Another paths i used in the past were
      /etc/php/7.0/apache2/php.ini
      /etc/php5/apache2/php.ini

      Is there any command as
      php -i | grep php.ini
      that works for any Linux installation and not just CLI for looking for a file?

      Reply
    5. Andres on April 19, 2019 7:35 pm

      I have Debian 9 and have changed the upload_max_filesize to 20M but still can’t upload a 4 megs file, an mp4, via WordPress installed in ISPConfig.

      It continues saying that the size of the file exceeds the allowed size of the site.

      I have changed the upload_max_filesize value in /etc/php/7.0/apache2/php.ini and also in /etc/php/7.0/cli/php.ini

      Any ideas of how it didn’t worked? Maybe there’s something i don’t realize right now.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.