What is the maximum upload file size in php?

PHP protects server performance by limiting file upload sizes, but the default limit is too low for many modern web applications. You’re likely to encounter this issue when a PHP application displays an error message asking you to increase the PHP max upload file size. There are various ways to increase the upload limit, including editing PHP configuration files directly. In this article, we’ll show you how to adjust PHP upload limits in cPanel & WHM quickly.

What Is “upload_max_filesize” in PHP?

The upload_max_filesize directive is a PHP variable set in the system and local php.ini files and user.ini files. These determine the PHP interpreter’s baseline configuration. As you might expect, upload_max_filesize limits the maximum allowable size of an uploaded file. The PHP default is 2 Megabytes, and you will have to increase it if you want to upload larger files via a PHP web application.

You may also have to adjust other directives, including:

  • post_max_size, which must be larger than upload_max_filesize.
  • memory_limit, which should be larger than post_max_size.

PHP directive values are expressed in bytes. If you set upload_max_filesize to 1000, the maximum size is 1000 bytes. However, you can also use the shorthand byte values K, M, and G for kilobytes, megabytes, and gigabytes. So, 1000K is 1000 kilobytes and 10G is 10 gigabytes.

In cPanel, you can edit PHP directives for locations and domains controlled by your account with the MultiPHP INI Editor, which you will find under Software in the main page menu.

Open the MultiPHP INI editor and select a location from the dropdown.

What is the maximum upload file size in php?

Scroll to the entry for upload_max_filesize and edit the associated value. Ensure that the value for post_max_size is larger than upload_max_filesize, and click apply at the bottom of the page.

What is the maximum upload file size in php?

How to Change the PHP Max Upload Size in WHM?

Whereas cPanel allows you to edit PHP directives in local directories, in WHM you can edit directives in the server’s main php.ini file. This affects all accounts using a particular PHP version.

To increase the PHP upload limit in WHM, open MultiPHP INI Editor from the Software section of the sidebar menu. In the dropdown, select a PHP version. PHP versions have independent configurations, so you must edit the max upload variable for all versions you wish to change.

What is the maximum upload file size in php?

Scroll to upload_max_filesize and edit the adjacent value before clicking Apply at the bottom of the page. Ensure that post_max_size is at least as large.

To learn more about editing PHP directives and what the customizable directives do, take a look at the MultiPHP INI Editor for WHM documentation.

As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You’ll find us on Discord, the cPanel forums, and Reddit. Be sure to also follow us on Facebook, Instagram, and Twitter.

Aug 23, 2022

Edvinas B. & Prasasti P.

3min Read

Download eBook: Speed Up Your Website. 8 Practical Tips That Work

When you try running a script, plugin, or uploading large files to your website, you might encounter an error. One of the possible causes of this issue – the upload exceeds the default maximum file size configuration on your web server.

In this article, we will show you three easy ways to increase the size limit by modifying the PHP maximum upload size.

  • Why Change the PHP Max Upload Size?
  • How to Change the Maximum Upload Size for PHP Scripts?
    • Option 1. Changing Maximum Upload File Size via hPanel
    • Option 2. Altering PHP Parameters Using cPanel
    • Option 3. Changing PHP Post Max Size via the .htaccess File
  • How to Check the Maximum File Size Value?

Why Change the PHP Max Upload Size?

The default maximum upload file size may vary depending on your hosting provider, usually staying around 128 MB. While this is typically enough for audio or picture files, you may encounter an error when uploading large files such as long videos.

If your site consists mainly of such content, you might want to increase the upload file size limit for more flexibility. On the other hand, you may wish to decrease the PHP max post size if you have limited storage.

How to Change the Maximum Upload Size for PHP Scripts?

There are several methods to modify your site’s maximum upload file size, and they may vary depending on your circumstances and preferences. Users can change PHP parameters by using the PHP configuration menu on their hosting control panel or manually modifying specific scripts that handle file uploads.

In most cases, you can change the PHP maximum file size limit by editing the php.ini file. If you are using a shared or cloud hosting plan, you’ll want to modify the .htaccess file instead.

Clearing the cookies will log you out of previously-visited websites. Thus, we recommend saving your login information before following this method.

Let’s take a look at three easy ways to edit your PHP settings and adjust your upload file size limit.

Option 1. Changing Maximum Upload File Size via hPanel

  1. To modify file upload limitations in Hostinger’s hPanel, click Manage on the Hosting panel and look up PHP Configuration in the Advanced section.
What is the maximum upload file size in php?
  1. Open the PHP Options tab. Users can change various limits and parameters on this page, including max execution time and memory limit.
What is the maximum upload file size in php?
  1. To change the maximum size for uploaded files, search for the uploadMaxFilesize field. Choose your desired data size from the drop-down menu. In the example below, the default size is set to 512 MB.
What is the maximum upload file size in php?
  1. Another option you might want to change here is postMaxSize. It controls the maximum size of files uploaded using the POST method. 
What is the maximum upload file size in php?
  1. Don’t forget to click Save at the bottom right corner of the page after you finish editing the settings.

Important! Note that the postMaxSize should always be larger than uploadMaxFilesize to avoid errors when uploading data.

Option 2. Altering PHP Parameters Using cPanel

  1. Access your cPanel dashboard and find Select PHP Version in the Software section. In this menu, users can change their PHP version, choose which extensions to activate, and change other PHP-related settings.
What is the maximum upload file size in php?
  1. Click the Options tab and search for post_max_size and upload_max_filesize. Choose your desired file upload limits from the dropdown menu.
What is the maximum upload file size in php?

Option 3. Changing PHP Post Max Size via the .htaccess File

  1. To change your post size limits using PHP scripts, navigate to File Manager in your hPanel.

What is the maximum upload file size in php?

  1. Open the public_html folder and find .htaccess.
What is the maximum upload file size in php?
  1. Open the file and insert the following PHP scripts:

php_value upload_max_filesize  XXM

php_value post_max_size XXM

  1. Change the “XX” into your desired size.
  2. Once you’re done with the configuration, click Save & Close.

Pro Tip

You can also edit .htaccess via an FTP client like FileZilla. If you can’t find the .htaccess file, configure your control panel or FTP client to display hidden files.

How to Check the Maximum File Size Value?

After changing the settings of your uploaded file size limits, we need to confirm them with the phpinfo() function to ensure they’re already implemented on the system. Simply create a new PHP file in the public_html directory of your site and insert the following PHP code:

<?php
    phpinfo();
     phpinfo(); 

You can name the file anything you want. In this example, we named it phpinfo.php. To access the file we just created, just add /phpinfo.php at the end of your site’s domain. It may look like this: http://yoursite.com/phpinfo.php.

What is the maximum upload file size in php?

You’ll see two columns — local value and master value. Local values are set within .htaccess and override the master values which are set within the php.ini file. Pay no mind to the master values and seek the local values for upload_max_filesize and post_max_size instead.

If the local values of both parameters are the same as you configured, you have successfully changed your website’s PHP file size limits.

Conclusion

By modifying PHP settings on your web server, you may no longer encounter errors during file upload processes. This method lets you submit larger files to the web server by increasing the default limit for uploads. Alternatively, you can decrease it to reserve storage space.

If you have questions or other tips and tricks about this topic, leave them in the comment section below.

Edvinas is a professional mentor and trainer of customer support agents. When he's not teaching the secrets of providing exceptional service, he likes to travel the world and play basketball.

Pras is a Digital Content Writer at Hostinger. With his IT education and experience as a website administrator, he hopes to share his knowledge with other tech enthusiasts. In his free time, Pras likes to play video games.

How can I upload more than 2 MB in PHP?

by default PHP will not handle file uploads larger than 2MB, if one requires PHP to handle larger files then one must set upload_max_filesize and post_max_size in your php. ini file to be larger than 2MB.

What is the maximum file uploading limit?

The maximum file size limit for uploads to Box varies depending on your account type: Free personal: 250 MB. Starter: 2 GB. Business: 5 GB.

How can upload file size in PHP?

The filesize() function in PHP is an inbuilt function which is used to return the size of a specified file. The filesize() function accepts the filename as a parameter and returns the size of a file in bytes on success and False on failure.

Is 6 upload file size limit?

By default, IIS web server allows for limited file size to be uploaded to the web server. For IIS 6 and IIS 7, the default maximum file upload size is 4 MB and 28.6 MB respectively.