1. Home
  2. Blog
  3. Uploaded File Exceeds upload_max_filesize in php.ini: How to Fix It

Uploaded File Exceeds upload_max_filesize in php.ini: How to Fix It

The error “The uploaded file exceeds the upload_max_filesize directive in php.ini.” means the file is larger than the upload limit PHP allows; the fix is to raise upload_max_filesize and post_max_size together. In this article, we explain how to do this with php.ini, .user.ini, .htaccess, Nginx and your hosting panel.

By meomanWordPress since 2008

This error appears when the file you upload is larger than PHP’s upload_max_filesize value; PHP ships with low default file upload limits such as 2M, and some hosting plans do not raise this value. To fix it, increase upload_max_filesize and post_max_size together in php.ini, .user.ini, .htaccess or your hosting panel (in cPanel: Select PHP Version > Options).

Server administrators use these limits as a safety barrier to prevent memory leaks and server lockups. If the limits are set too high, many large uploads at the same time can exhaust the server’s RAM and bring down every website on it. That is why you must keep server resources in mind when raising them.

The error message comes directly from the PHP engine and states that the “upload_max_filesize” directive has been exceeded. This means the file reached the server but PHP refused to process it. To solve the problem, you need to raise the size limits at every gate the file passes through (PHP, the web server and the application).

  • Default limits set to protect server resources.
  • Strict configuration policies on shared hosting plans.
  • Configuration files that are reset after PHP version updates.

The Impact of Memory Limits

File uploads are not limited by file size alone; the file also has to be processed in the server’s memory (RAM). If your memory_limit is lower than the size of the file you are uploading, you may get “Fatal Error” messages while the file is being processed, even if the upload itself completes.

  • Always keep memory_limit higher than the file size.
  • Increase the PHP script execution time (max_execution_time) for large files.
  • Optimize the input time (max_input_time) according to upload speed.
MethodFile NameKey ParameterDifficultyArea of impact
PHP configurationphp.iniupload_max_filesizeMediumEntire server
Apache directives.htaccessphp_value upload_max_filesizeEasyPer directory
User INI file.user.iniupload_max_filesizeEasyPer directory
Nginx settingsnginx.confclient_max_body_sizeAdvancedWeb server
Hosting panelcPanel/PleskPHP Selector / OptionsVery easyUser account

The Definitive Fix: Editing php.ini

The php.ini file, located in your server’s root directory or PHP installation folder, is the main control panel that defines all PHP behavior. If you have FTP or SSH access to this file, this is the most professional way to change the limits permanently. After making changes, you may need to restart the server (Apache or Nginx).

Search the file to find the relevant lines and update the values to suit your needs. For example, if you want to upload a 64MB file, setting the value to 128MB gives the system comfortable headroom. Remember that post_max_size must always be greater than or equal to upload_max_filesize.

Many shared hosting providers do not allow access to the main php.ini file. However, you can try to override these settings by creating a .user.ini file yourself (php.ini on some servers) in your site’s root directory (public_html). Some server configurations detect this local file automatically and apply its settings.

  • upload_max_filesize = 128M
  • post_max_size = 130M
  • memory_limit = 256M

Optimizing Input Times

Uploading large files can take a long time depending on connection speed. If PHP’s default 30-second timeout runs out, the upload is cut off. To prevent this, you should also raise the timeout limits in php.ini.

  • max_execution_time = 300 (in seconds).
  • max_input_time = 300 (time allowed for data input).
  • Allocating enough buffer memory to process data packets.

Raising the Limit with .htaccess

If your server runs on Apache and your access to php.ini is restricted, the .htaccess file can be a lifesaver. This file sends directory-level instructions to the server and lets you change PHP settings for that location. It is usually a hidden file in the root directory of WordPress sites.

The “php_value” commands you add to .htaccess make the server update its PHP configuration for that specific website. This method is quite effective, but a single wrong character can cause your site to return a “500 Internal Server Error”. So always back up the file before making changes.

php_value commands only work if PHP runs as an Apache module (mod_php); on servers using PHP-FPM or CGI they cause a 500 error, in which case you should put the same values in a .user.ini file. If “AllowOverride” is disabled, .htaccess is not read at all. If the code you add has no effect, your server administrator needs to enable this feature.

  • php_value upload_max_filesize 128M
  • php_value post_max_size 128M
  • php_value memory_limit 256M

Avoiding Misconfiguration

When adding code to .htaccess, it is recommended to place it between <IfModule mod_php7.c> or <IfModule mod_php.c> blocks. This keeps your site from crashing if the server’s PHP version changes or the module is disabled.

  • Add the code at the very top or bottom of the file.
  • Use only K, M or G as the unit (128M is correct, 128MB is wrong).
  • After making changes, clear your browser cache and test.
Related serviceWordPress Security Settings

wp-config.php and Theme Functions for WordPress

Another way for WordPress users to get around upload limits is to use the application’s own configuration files. Besides the WordPress database connection, the wp-config.php file can also contain ini_set functions that set PHP limits. However, upload_max_filesize and post_max_size are PHP_INI_PERDIR directives and cannot be changed at runtime with ini_set; this method only works for settings such as memory_limit and max_execution_time.

Similar code can also be added to your theme’s functions.php file. However, this is usually not a permanent solution, because the code can be wiped out when the theme is updated. The same restriction applies here: ini_set lines in functions.php do not raise the upload limit either.

For the upload limit, use php.ini, .user.ini, .htaccess or your hosting panel. If none of these work, the server’s main configuration is overriding your local settings and your hosting provider needs to raise the value.

  • define( 'WP_MEMORY_LIMIT', '256M' ); (raises memory, not the upload limit)
  • ini_set lines have no effect on upload_max_filesize and post_max_size.
  • @ini_set( 'max_execution_time', '300' );

Checking the WordPress Media Library

In the WordPress dashboard, go to “Media -> Add New” and you will see the “Maximum upload file size” at the bottom. You can check right there whether your changes have worked.

  • After making changes, confirm that the number in the dashboard has been updated.
  • Check whether any plugins override these limits.
  • If necessary, review the limit settings of plugins such as “All-in-One WP Migration”.

For users who do not want to deal with code or have no FTP access, the WordPress plugin directory offers many practical solutions. Most of these plugins cannot exceed the server’s PHP limit; they only adjust WordPress’s limit up to what the server allows. Big File Uploads, however, can upload files larger than that limit by splitting them into chunks (chunked upload).

When choosing a plugin, pay attention to how recently it was updated and to user reviews. Reliable, well-performing plugins include:

  • Increase Maximum Upload File Size: Updates the limits when you type the size you want into a single box.
  • WP Maximum Upload File Size: Detects your server limits and helps you raise them to the highest possible value.
  • Big File Uploads: Offers a setup optimized especially for large video and archive files.
  • Tuxedo Big File Uploads: The former name of the Big File Uploads plugin, not a separate plugin.
  • All-in-One WP Migration: Offers its own file upload engine and a limit increase option for site migrations.

Source: WordPress Plugin Directory

Setting client_max_body_size on Nginx Servers

If your website runs on Nginx instead of Apache, you may keep getting a “413 Request Entity Too Large” error no matter how much you raise the PHP settings. For security reasons, Nginx strictly checks the size of data sent by the client, and the default limit is usually 1MB.

To fix this, you need to update the client_max_body_size parameter in the Nginx configuration file (nginx.conf) or in your site’s own server block file. This setting directly controls the body size of the HTTP request.

After making the change, you must reload the Nginx service. This usually requires root access via SSH, so shared hosting users may not be able to change this setting themselves.

  • Add it inside the http, server or location block.
  • Add or update the line client_max_body_size 128M;.
  • Test the configuration with the sudo nginx -t command and apply it with sudo systemctl reload nginx.

How Nginx and PHP-FPM Work Together

On Nginx servers, PHP is usually run through PHP-FPM. That is why Nginx’s client_max_body_size setting and the upload_max_filesize setting in PHP-FPM’s php.ini must match each other.

  • The Nginx limit should not be lower than the PHP limit.
  • Check the error logs to determine whether the bottleneck is Nginx or PHP.
  • Optimize FastCGI buffer settings for large data transfers.

Using Hosting Control Panels (cPanel and Plesk)

Modern hosting panels let you manage PHP settings through a visual interface instead of dealing with complex configuration files. cPanel users can raise the limits in seconds with the “Select PHP Version” or “MultiPHP INI Editor” tools.

In Plesk, all directives are listed under the “PHP Settings” tab. Just select the value you want and click “Apply”. This is the most reliable method, because it automatically gets around server-side permission problems.

If you cannot see these options in your panel, your hosting provider may have restricted this permission. In that case, you can open a support ticket with a request such as “Please increase upload_max_filesize and post_max_size to 128MB.”

  • Go to cPanel -> Software -> Select PHP Version -> Options.
  • Go to Plesk -> Domains -> PHP Settings.
  • Remember to click “Save” after changing the values.

Source: MDN Web Docs - 413 Payload Too Large

Frequently Asked Questions

1. What is the difference between upload_max_filesize and post_max_size?

upload_max_filesize sets the maximum size of a single file, while post_max_size limits the total amount of data sent in an HTTP POST request. The second value should always be larger so it can cover the uploaded file plus the form data.

2. Why aren’t my changes taking effect?

A php.ini change takes effect when PHP-FPM or the web server is restarted; a .user.ini change takes effect within 5 minutes by default (user_ini.cache_ttl). Also, on shared hosting, the provider’s main configuration may be overriding your local settings.

3. Will increasing this limit slow down my site?

Raising the limit alone does not affect site speed, but if many large files are uploaded at the same time, server resources (CPU/RAM) can be strained. This can cause temporary slowdowns, especially on servers with modest hardware.

4. What is a safe limit value?

For general use, 64MB or 128MB is plenty. However, if you run a video-focused site, you may need to raise it to 512MB or more; in that case, you should back up server security with extra measures (such as a WAF).

5. What should I do if the error persists?

If you still get the error after all the code changes, the problem may be caused by a restriction at the web server (Nginx/Apache) level. The right next step is to ask your hosting company to review the server logs.

In summary
The “uploaded file exceeds the upload_max_filesize directive in php.ini” error is a technical restriction that is easy to fix by updating the size limits in your PHP configuration. With the right changes via php.ini, .htaccess or your hosting panel, you can bring your website’s upload capacity in line with current standards.