BuddyDev

Search

To change the maximum upload file size for PHP, you need to modify two PHP configuration settings: upload_max_filesize and post_max_size. Here are the steps you can follow:

Step 1:- Locate the PHP configuration file called php.ini. If you are not sure where this file is located, you can create a new PHP file with the following code:

Then, open the file in a web browser, and look for the “Loaded Configuration File” value. This will tell you where the php.ini file is located.

Here is a screenshot showing the same.

Step 2:- Open the php.ini file in a text editor.(e.g nano php.ini). You will need administrative privilege to edit it(e.g sudo user)

Step 3:- Search for the upload_max_filesize setting. This sets the maximum size of an individual file that can be uploaded. By default, this is usually set to 2M (2 megabytes).

Step 4:- Change the value to the desired maximum file size. For example, to set the maximum file size to 20 megabytes, you can use the following:

Note that you can use different size units, such as K for kilobytes or G for gigabytes.

Step 5:- Search for the post_max_size setting. This sets the maximum size of the entire HTTP POST request, which includes the uploaded files. By default, this is usually set to 8M.

Step 6:- Change the value to the desired maximum request size. For example, to set the maximum request size to 25 megabytes, you can use the following:

Step 7:-  Save the php.ini file and restart your web server. This will apply the changes.

Congratulations!, your PHP scripts will be able to handle larger file uploads now.

References:-

  • https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
  • https://www.php.net/manual/en/ini.core.php#ini.post-max-size