How to fix "The uploaded file exceeds the upload_max_filesize directive in php.ini" in WordPress
PHP refused a file larger than its upload_max_filesize setting, and WordPress passed the message on. Raise upload_max_filesize and post_max_size together, in .htaccess, in .user.ini or in your host's PHP settings, depending on how PHP runs. Nothing on the site has been lost.
- By
- WP Ministry
- Published
- Tested on
- WordPress 7.1.3, PHP 8.3.35
In short
- Nothing is lost. The server refused one file, and the site is as it was.
- The figure under Media, Add Media File is the limit you are under.
- Two PHP settings decide it, upload_max_filesize and post_max_size. Raise both.
- An ini_set() line in wp-config.php changes neither of them.
- .htaccess works where PHP is part of Apache, and .user.ini where it runs as FPM or CGI.
- One large file can go in over SFTP and be added to the Media Library with WP-CLI.
PHP, the language WordPress runs on, refuses any uploaded file larger than its upload_max_filesize setting. WordPress then gives PHP's reason word for word: "The uploaded file exceeds the upload_max_filesize directive in php.ini." You meet it when you install a plugin or a theme from a .zip file, or add a file to the Media Library.
Nothing has been lost or changed. The server turned the file away before WordPress did anything with it, so the site is as it was a minute ago. To get the file in, raise the limit or bring the file in another way.
Other messages from the same limit
The Media Library's own uploader is told the limit in advance. It stops a larger file in your browser and says that the file "exceeds the maximum upload size for this site." The limit is the same one, and so are the fixes.
The message on this page appears where nothing checks first: under Plugins, Add Plugin, Upload Plugin, when you upload a theme, in the Media Library's browser uploader, and when something has told WordPress a higher figure than PHP allows.
WordPress keeps the message in a list of what can go wrong with an upload. Three of its neighbors are "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.", "The uploaded file was only partially uploaded." and "Missing a temporary folder." Those have other causes, and the fixes here do not clear them.
Two more are easy to take for this one. A file larger than PHP's second limit, post_max_size, makes a plugin upload fail with "The link you followed has expired." On nginx, a request larger than client_max_body_size is answered "413 Request Entity Too Large" before PHP sees the upload. The nginx server block generator writes that setting into the server block it builds.
See the limit you are under
Go to Media, then Add Media File. Under the upload box WordPress prints the limit, for example "Maximum upload file size: 2 MB." It is the smaller of two PHP settings: upload_max_filesize, the largest single file, and post_max_size, the largest form, files included. PHP's own defaults are 2M and 8M.
To see both, go to Tools, then Site Health, and open the Info tab. The "Media Handling" section lists "Max size of an uploaded file", "Max size of post data allowed" and "Max effective file size". The "Server" section has "PHP SAPI", which says how PHP runs on your server, and so which fix is yours:
apache2handler: PHP is part of Apache. Use the.htaccessfix.fpm-fcgiorcgi-fcgi: PHP runs as FPM or CGI. Use the.user.inifix.- Anything else: use your host's PHP settings.
Where it goes wrong
A page request passes through each of these in turn. This one comes from PHP, the language WordPress runs on.
- Browser
- DNS
- HTTPS
- CDN or firewall
- Web server
- PHP (this error comes from here)
- WordPress
- Database and files
What causes it
PHP's upload limit is lower than the file
CommonPHP accepts no uploaded file larger than upload_max_filesize. Its own default is 2M, which a plugin's .zip file, a video or a long PDF soon passes.
Fix: Raise the limits in .htaccess, or Raise the limits in .user.ini, or Change it in your host's PHP settings, or Bring one large file in without the upload form
The limit was raised somewhere PHP does not read
CommonThese settings can be set in PHP's own configuration, in .htaccess or in .user.ini, and each of the last two is read only one way of running PHP. A line in wp-config.php or in a theme's functions.php changes nothing.
Fix: Raise the limits in .htaccess, or Raise the limits in .user.ini
The host fixes the limit for your plan
SometimesA host can set the limit in the server's configuration in a way that no file in your site can override. Then only the host can raise it.
Fix: Change it in your host's PHP settings, or Ask the host to raise it, or Bring one large file in without the upload form
How to fix it
Raise the limits in .htaccess
- Takes care
- Back up first
- About 10 minutes
- Steps tested on WordPress 7.1.3
This works where PHP runs as part of Apache. Where PHP runs another way, the lines are skipped and nothing changes.
Step 1: Open .htaccess
It is in the site's main folder, beside
wp-config.php. Its name begins with a dot, so set your file manager to show hidden files if you cannot see it.Step 2: Add these lines above "# BEGIN WordPress"
Choose a figure with room above your largest file, and raise the two together. Never leave
post_max_sizebelowupload_max_filesize: the form carries the file and a little more. The first and last lines tell a server that runs PHP another way to skip the two in the middle instead of failing on them..htaccess<IfModule mod_php.c> php_value upload_max_filesize 64M php_value post_max_size 64M </IfModule>Step 3: Reload Media, then Add Media File
The figure now reads "Maximum upload file size: 64 MB." Upload the file again.
If the figure has not moved, PHP does not take settings from .htaccess on your server. Remove the lines and use the next fix. If you would rather not edit the file by hand, the .htaccess generator gives you a complete .htaccess with these lines above WordPress's own block, built in your browser.
To undo it: Remove the four lines from .htaccess.
Raise the limits in .user.ini
- Easy
- Low risk
- About 10 minutes
Where PHP runs as FPM or CGI, it reads settings from a file named .user.ini. PHP as part of Apache never reads that file.
Step 1: Open or create .user.ini in the site's main folder
If the file is there already, keep what it holds.
Step 2: Add these two lines
.user.iniupload_max_filesize = 64M post_max_size = 64MStep 3: Wait five minutes, then reload Media, then Add Media File
By default PHP looks at
.user.iniagain only every 300 seconds, so the change does not show at once. When the figure has gone up, upload the file again.
If the figure has not moved after ten minutes, the file is not being read, or the host does not let it change these settings. Use the host's own settings instead.
To undo it: Remove the two lines from .user.ini.
Change it in your host's PHP settings
- Easy
- Low risk
- About 10 minutes
Step 1: Find the PHP settings page in your hosting panel
Many hosts have one, under a name such as "PHP settings" or "PHP options".
Step 2: Set upload_max_filesize and post_max_size
Give both a figure larger than your file, and save. If the page will not go as high as you need, that ceiling belongs to your plan.
Step 3: Reload Media, then Add Media File
Check the figure, then upload the file again.
Ask the host to raise it
- Easy
- No risk
- About 15 minutes
A host can set the limit where no file of yours overrides it. Then nothing above changes the figure, and only the host can.
Step 1: Write to support
Give the size of the file. Ask them to set
upload_max_filesizeandpost_max_sizeabove it for your site, and whether your plan allows it.Step 2: Send what Site Health shows
Copy the two figures and "PHP SAPI" from Tools, Site Health, Info, so that they see what you see.
Bring one large file in without the upload form
- Takes care
- Low risk
- About 15 minutes
- Steps tested on WordPress 7.1.3
The limit applies to what a browser sends through a form. A file that reaches the server over SFTP is not held to it.
For a plugin or a theme, unzip it and upload its folder, as the page on "The link you followed has expired." describes. A file for the Media Library needs one more step, because the library lists only the files WordPress has a record of. WP-CLI makes that record. It needs SSH access to the server: how to use WP-CLI covers getting started.
Step 1: Upload the file over SFTP
Put it in a folder of its own on the server, such as
incomingin your home folder.Step 2: Import it
In the folder WordPress is installed in, run this with the path to your own file.
WP-CLI answers "Success: Imported 1 of 1 items." and the file is in the Media Library.
bashwp media import ~/incoming/large-video.mp4Step 3: Delete the copy you uploaded
The import copies the file into WordPress's uploads folder, so the one in
incomingis no longer needed.
To undo it: Delete the file from the Media Library.
When to get help
If the figure under Media, Add Media File stays where it is whatever you change, the limit is set above anything you can reach, and only the host can move it. If the host will not, and large files are part of how the site works, the real question is which hosting the site needs, and that is worth a second opinion before you pay to move.
Common questions
I raised the limit, the message has gone, and the upload still fails. Why?
Only upload_max_filesize went up. PHP discards a form larger than post_max_size whole, file included, so nothing is left to report. The Media Library's browser uploader goes back to the upload screen with no message, and a plugin upload says "The link you followed has expired." Raise both settings.
How high should I set the limit?
Above the largest file you expect to upload. PHP's manual adds two things that matter for large files. memory_limit should generally be larger than post_max_size: the page on the memory error shows how to raise it. And PHP allows 60 seconds by default to receive a request, upload included, so a large file on a slow connection can run out of time. That setting is max_input_time.
Does a multisite network have a limit of its own?
Yes. In the network admin, under Settings, then Network Settings, "Max upload file size" applies to every site on the network, and it is 1500 KB until someone changes it. A file over it gets a different message: "This file is too big. Files must be less than 1500 KB in size." Raise PHP's limits first, then that one.
- GuideLocked out of WordPress admin: find which lockout you have and get back in
- GuideSlow WordPress admin: how to find the cause and fix it
- ResourceWooCommerce checkout is down: a runbook
- GuideWordPress site not showing up on Google: what to check, in order
- Guideadmin-ajax.php high CPU usage in WordPress: how to find what is calling it
- GuideHow to change WordPress permalinks without breaking your old links

