WordPress HTTP Error on Image Upload: Find the Real Cause
Find the cause of a WordPress HTTP error on image upload: read the status code, then check firewall, memory, post_max_size, Imagick, permissions and filename.
“HTTP error” is not a cause. It is the uploader saying it sent your file to the server and got back an answer it could not read as success, and at least seven unrelated failures produce it. Guessing between them is why people spend an afternoon raising upload_max_filesize on a site whose real problem is a firewall rule.
Current WordPress no longer prints the bare words “HTTP error”. WordPress 7.1.4 uses these messages instead, and none of them names the cause either:
- “Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.”
- “The server cannot process the image. This can happen if the server is busy or does not have enough resources to complete the task. Uploading a smaller image may help. Suggested maximum size is 2560 pixels.”
- “An error occurred in the upload. Please try again later.”
- In the block editor: “Media upload failed. If this is a photo or a large image, please scale it down and try again.”
Which one you get depends on which uploader you used as much as on what broke. In the media window (the Media Library grid and the Add Media dialog), any failed status on an image, a firewall’s 403 included, shows the “cannot process the image” text. On the Media → Add New Media File screen the same 403 gave “Unexpected response from the server” in our test. The first is read from the WordPress 7.1.4 uploader scripts, not run. So read the status code, not the sentence.
TL;DR: Open the Network tab and upload again before touching any setting. The status code sorts the causes into four groups in seconds: a 403 or 406 means a firewall or security rule, a 500, 502, empty answer or timeout means PHP ran out of memory or time, a 413 means a size limit, and a 200 with junk before the JSON means a plugin printed something it shouldn’t. Each branch below has one check, in the order worth trying them.

First: read the actual response
Open your browser’s developer tools, go to the Network tab, and upload the file again. The Media Library sends it to async-upload.php. The block editor sends it to the REST API at /wp-json/wp/v2/media. Whatever comes back is your diagnosis.
| What you see | What it means | Go to |
|---|---|---|
| 403 or 406, HTML body | A firewall or mod_security rule rejected the request | Branch A |
| 500, 502, an empty response, or a cut-off body | PHP crashed or ran out of memory while processing | Branch B |
| The request never finishes or times out | An execution time limit, usually with large files | Branch B |
| 413 | The request body was over a server limit | Branch C |
| 200, but the body has HTML or a PHP notice before the JSON | A plugin or theme printed output into the response | Branch D |
WordPress also retries on its own. When an image upload gets a 5xx answer that carries an X-WP-Upload-Attachment-ID header, WordPress knows the file was saved and only the resizing failed. It asks the server to finish the image sizes up to five more times, then deletes the half-made attachment and shows the “cannot process the image” or “Media upload failed” message. That is read from the WordPress 7.1.4 uploader scripts, not run. So in the Network tab you may see several follow-up requests after the first failure. Judge the cause by the first one.
If you can’t get to the browser tools, turn on logging in wp-config.php first. Change the existing WP_DEBUG line to true (a second define does nothing, because PHP keeps the first value) and add the other two, or let the WP_DEBUG code generator write them:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Reproduce the upload, then read wp-content/debug.log, or wherever WordPress writes debug.log on your host. A fatal error line names the branch outright. If the line is dense, paste it into the error log decoder, which explains the common fatal patterns.
Branch A: a firewall or mod_security rule
A 403 with an HTML page in the body means the request never reached WordPress. Something in front of it (mod_security, Cloudflare, Wordfence, Sucuri, or your host’s own rule set) decided the upload looked malicious.
The check: temporarily deactivate any security plugin and upload again. If that changes nothing, the rule lives at the server level, and you need your host to look at the mod_security audit log for the time of the failed upload. They can whitelist the specific rule ID.
By product: Cloudflare’s block page shows a Ray ID at the bottom. If the site is yours, filter Security Events in the Cloudflare dashboard by that Ray ID to find the event for that request. Those logs are sampled, so a missing entry does not prove Cloudflare let the request through. Wordfence lists blocked requests under Tools → Live Traffic, with the firewall rule each one broke, so check it before deactivating anything. Either way, the goal is the rule ID or event, not just proof that something blocked it.
You’ll find snippets telling you to put this into .htaccess:
SecFilterEngine Off
SecFilterScanPOST Off
Those are ModSecurity 1.x directives. ModSecurity 2 dropped them, and its on/off switch is now SecRuleEngine, so on a modern server those lines do nothing or cause a 500 error. SecRuleEngine itself doesn’t work in .htaccess either: the ModSecurity 2 manual lists the few rule directives allowed there, only when the module was built to accept them, and SecRuleEngine is not one of them. Ask the host; don’t paste.
Branch B: PHP memory or execution limits
This branch has a clear tell: it’s intermittent. The same file uploads on the third try, or a 2MB photo fails while a 6MB PDF goes through. Hard configuration limits fail the same way every time. Memory failures don’t, because what’s available depends on what else the server is doing.
Why images specifically: WordPress doesn’t just store the file. It decodes it into raw pixels to build every intermediate size. In our 2026-11-16 test (WordPress 7.1.4, PHP 8.3.36, WordPress Playground) a 12-megapixel JPEG produced thumbnail, medium, medium_large, large, 1536x1536 and 2048x2048, plus a -scaled copy because it was over the 2560-pixel big_image_size_threshold. Themes and plugins add more with add_image_size (WooCommerce adds its own, for example). Why one photo becomes eight files explains the list, the image sizes cheat sheet gives every default dimension, and why WordPress adds -scaled to images covers that threshold.
Memory scales with pixel count, not file size on disk. A heavily compressed 12MP JPEG and a barely compressed one decode to the same bitmap. To put numbers on it, we decoded JPEGs at four camera resolutions on 2026-11-06 and read the process’s memory from the operating system. That run used Python 3.12 and Pillow 11.3.0, not PHP’s GD, because that machine had no PHP. Pillow does the same decode into a full bitmap, so read these as the right order of magnitude, not as exact GD figures. The test images were synthetic, so their size on disk is not shown. The two memory columns measure different things. The first is what decoding that one image added. The second is the whole process at its peak after one resize, including the roughly 29.5MB that Python and Pillow used before any image was opened.
| Resolution | Megapixels | Added by the decode | Whole process at peak (decode + one resize) |
|---|---|---|---|
| 1600×1200 (small web photo) | 1.9MP | +8.8MB | 53.5MB |
| 4032×3024 (12MP phone photo) | 12.2MP | +48.1MB | 139.1MB |
| 6000×4000 (24MP DSLR/mirrorless) | 24.0MP | +93.3MB | 247.9MB |
| 8064×6048 (“48MP” phone sensor) | 48.8MP | +187.8MB | 435.0MB |
Whether that memory counts against PHP’s memory_limit depends on the image library and on how PHP was built:
- GD bundled with PHP allocates through PHP’s own memory manager (
gdMallocis defined asemallocin PHP’s source), so the pixels count againstmemory_limit. That is read from the PHP 8.3 source, not run. Site Health shows it as “GD version: bundled (2.1.0 compatible)”. - GD built against a separate libgd does not. In our 2026-11-16 Playground run (GD 2.3.3,
memory_limit256M), PHP’s own counter rose by 0MB when GD decoded a 48.8-megapixel JPEG, while a 50MB PHP string, used as a control, showed +50.1MB. WordPress then built every size of all four test images without error. On builds like that, the limit you hit is the server’s RAM or the host’s per-process cap. - ImageMagick also works largely outside PHP’s memory count, and has its own limits (Branch E).
When PHP’s limit is the wall, the log says Allowed memory size of N bytes exhausted. When the server’s limit is the wall, the PHP process is killed, the browser usually gets a 500 or 502, and PHP never gets to write a log line.
For image work, WordPress raises PHP’s limit to WP_MAX_MEMORY_LIMIT before resizing, if the host allows PHP to change memory_limit at runtime. That constant defaults to 256M, or to the current limit if it’s already higher (read from the 7.1.4 source). WP_MEMORY_LIMIT covers ordinary page loads. So the constant that matters for uploads is the second one in this block, which goes above the “stop editing” line:
define( 'WP_MEMORY_LIMIT', '256M' );
define( 'WP_MAX_MEMORY_LIMIT', '512M' );
Neither constant can raise a wall the host has fixed in place. If the host locks PHP’s memory_limit directive at 128M, WordPress keeps 128M. Check the real value in Tools → Site Health → Info → Server, in the “PHP memory limit” row (WordPress.org’s Site Health documentation explains each row). Fixing the allowed memory size exhausted error covers raising it in wp-config.php, .user.ini or .htaccess, and how to tell when the host is overriding you. If PHP’s own limit is the ceiling, only the host can move it. Uploading a smaller image, as WordPress’s own message suggests, is the other fix.
Branch C: file size and post limits
Check the actual numbers under Tools → Site Health → Info → Media Handling, in the “Max size of an uploaded file” and “Max size of post data allowed” rows. Two PHP settings matter, and people usually change only one:
upload_max_filesize: the cap on a single file.post_max_size: the cap on the entire request body.

WordPress takes the smaller of the two and gives it to the uploader, which checks each file in the browser before sending it. A file over that size never leaves your computer. You get “[file name] exceeds the maximum upload size for this site.” instead, which is clear. The block editor uses the same number. So a vague error on a big file usually means one of these:
- The request body went over
post_max_sizeeven though the file was under it, which can happen when both limits are set to the same value. The PHP manual says that when post data is larger thanpost_max_size,$_POSTand$_FILESare empty. WordPress runs, finds no file, and the uploader gets an error instead of the attachment. Setpost_max_sizecomfortably larger thanupload_max_filesize. - A limit outside PHP is lower than PHP’s. NGINX’s
client_max_body_sizedefaults to 1m and answers a larger request with a 413 (Request Entity Too Large). The NGINX manual notes that browsers cannot correctly display that error, which is why the uploader only reports something vague. It is set in thehttp,serverorlocationblock of the server configuration, so on shared hosting only the host can raise it. A CDN or proxy in front of the site can have its own cap too.
Where you change the PHP values depends on your server:
| Server | What works | What doesn’t |
|---|---|---|
| Apache with mod_php | php_value lines in .htaccess | |
| Apache with PHP-FPM or CGI | A .user.ini file, or the host’s PHP settings panel | php_value in .htaccess gives a 500 error |
| LiteSpeed | php_value lines in .htaccess (LiteSpeed’s PHP handler accepts them without a 500), or the host’s panel | LiteSpeed’s cPanel documentation advises against .user.ini |
| NGINX with PHP-FPM | A .user.ini file, or the host’s PHP settings panel | .htaccess, which NGINX does not read |
The .htaccess form:
php_value upload_max_filesize 64M
php_value post_max_size 128M
The .user.ini form, in the folder that holds wp-config.php:
upload_max_filesize = 64M
post_max_size = 128M
PHP reads .user.ini files only under CGI or FastCGI (PHP-FPM is FastCGI), and re-reads them every 300 seconds by default, so wait five minutes before re-checking Site Health. The WordPress max upload size tool builds matching values for php.ini or .user.ini, .htaccess and wp-config.php from one target size, and how to increase the upload limit on any host covers host panels and the NGINX setting.
Branch D: a plugin printed output into the response
If the upload request comes back 200 but the body starts with a PHP notice, a warning, or a stray bit of HTML before the JSON, the uploader can’t parse it. WordPress may well have saved the file (the “Unexpected response” message says as much), but the browser can’t tell. The usual source is a plugin or theme printing a PHP warning while display_errors or WP_DEBUG_DISPLAY is on, or a file with whitespace after a closing ?>.
The check: set WP_DEBUG_DISPLAY to false so warnings go to debug.log instead of into the response, then upload again. If that fixes it, read the log to see which plugin produced the warning and update or replace it. If not, bisect plugins. It is the same fault that makes the block editor say “The response is not a valid JSON response”; the block editor guide has the REST API checks.
Branch E: the image library (Imagick vs GD)
WordPress prefers ImageMagick when the PHP extension is present and falls back to GD. ImageMagick has its own limits, set in its policy file: memory, disk, image area, width and height. ImageMagick’s security policy documentation says an image over the area limit moves to a slower disk cache, while one over the width or height limit is rejected. A rejected image fails the resize, and WordPress only shows its general upload error. You’ll usually see this on large images while small ones work, which looks like Branch B but isn’t.
Force GD to test the theory:
add_filter( 'wp_image_editors', function ( $editors ) {
return array( 'WP_Image_Editor_GD' );
} );
Put that in a small must-use plugin or in functions.php, retry the upload, then remove it if nothing changes.
The trade-off: GD is not strictly better. With the GD bundled in PHP, the whole decoded image counts against memory_limit (Branch B), so a very large photo can fail on GD where ImageMagick, which keeps its pixels outside PHP’s count, would have worked. Switching can trade one failure for another. Treat it as a test first and a fix second.
Branch F: uploads folder permissions
Check this one first if the site was just migrated or moved by hand. If wp-content/uploads isn’t writable by the web server user, or a new year/month subfolder got the wrong owner, the write fails.
ls -ld wp-content/uploads
ls -ld wp-content/uploads/2026/11
Folders should normally be 755 and owned by the user PHP runs as. Don’t set 777 because a forum told you to. It fixes the symptom by making the folder writable by every account on the server, which on shared hosting is a real exposure.
Branch G: the filename
The cheapest check on the list, so do it early. Rename the file to plain lowercase letters, numbers and hyphens (no accents, apostrophes, ampersands, # or non-Latin characters) and upload again. Special characters sometimes trip a security rule or break on a filesystem with a mismatched encoding.
What not to do
Don’t start by deactivating every plugin. It’s disruptive, and it only tests Branch A and Branch D. The network response tells you more in five seconds.
Don’t add a random .htaccess handler line. The snippets that add a SetHandler or AddHandler line assume one host’s PHP setup. On the wrong server they take the whole site down with a 500.
Don’t accept “it worked on retry” as fixed. Intermittent success is the sign of Branch B, and it will come back when the server is busy or someone uploads something bigger.
Still stuck?
If the response is a clean 200 with valid JSON and the upload still fails, the break is after the file lands. Usually a plugin hooked into attachment processing (the wp_generate_attachment_metadata filter, listed in our WordPress hooks reference) throws a fatal, or an optimizer plugin calls an outside service that times out. Turn on WP_DEBUG_LOG, reproduce, and run the fatal through the error log decoder to see which file and which hook is responsible.
The same kind of fatal shows up differently depending on where in a request it happens. On a normal page load it gives a critical error screen, and in a few cases a blank white screen with no message at all. All three come down to one habit: PHP crashed, WordPress couldn’t say why on the page, and the answer is one debug.log line away. A site-wide “Error establishing a database connection” is a different failure; see the database connection guide.
Sources
- PHP manual: Core php.ini directives (post_max_size, upload_max_filesize, memory_limit)
- PHP manual: .user.ini files
- PHP source: ext/gd/libgd/gdhelpers.h, PHP 8.3 branch
- NGINX documentation: ngx_http_core_module, client_max_body_size
- LiteSpeed documentation: 500 Error (cPanel), PHP Per User php.ini in LiteSpeed Web Server
- ModSecurity documentation: Reference Manual (v2.x), including SecRuleEngine and the note on upgrading from 1.x
- Cloudflare documentation: Cloudflare Ray ID, WAF FAQ (why a request was blocked)
- Wordfence Help: Real-Time Live Traffic
- ImageMagick documentation: Security Policy (resource limits)
- WordPress Documentation: Site Health Screen
- WordPress 7.1.4 source: script-loader.php (upload messages), plupload/handlers.js, plupload/wp-plupload.js, media.php (wp_max_upload_size), default-constants.php (WP_MAX_MEMORY_LIMIT)
William Lopez is the founder of Odie Themes. He builds the free WordPress tools and themes on this site and has been on WordPress.org since December 2019.
FAQ
Questions
What does HTTP error mean when uploading images to WordPress?
It means the uploader sent your file to the server and got back something it could not read as a successful answer. Current WordPress words it differently, for example "Unexpected response from the server" or "The server cannot process the image", but every version describes the symptom, not the cause. A crashed PHP process, a firewall block, a size limit and stray output from a plugin can all produce the same message.
Why does the same image upload fine sometimes and fail other times?
Intermittent failures usually point to memory or CPU running short rather than a configuration limit. Resizing a large photo needs a burst of memory, and on shared hosting the amount available changes with server load. A hard limit like post_max_size fails the same way every time.
Does switching WordPress from Imagick to GD fix HTTP errors?
Sometimes, and only for one branch. ImageMagick can be held back by its policy file or low resource limits, and then it fails where GD succeeds. GD holds the whole decoded image in memory, though. With the GD that ships inside PHP, that memory counts against PHP's memory_limit, so switching can turn one failure into another. Treat the switch as a test first.
How do I know if my host firewall is blocking the upload?
Open your browser's network tools, upload the file, and look at the status code of the upload request: async-upload.php from the Media Library, or /wp-json/wp/v2/media from the block editor. A 403 or 406 with an HTML body means a web application firewall or mod_security rule rejected it. A 500, a 502 or an empty response points at PHP crashing instead.
Will increasing upload_max_filesize fix the HTTP error?
Rarely on its own. WordPress checks each file against the smaller of upload_max_filesize and post_max_size in the browser, before sending it, and shows a clear "exceeds the maximum upload size" message when a file is too big. A vague error on size more often means a limit outside PHP, such as NGINX's client_max_body_size, which answers with a 413. Raise both PHP values together, and ask the host about the server limit.
Can a filename cause a WordPress HTTP error?
It can. Accented characters, apostrophes, ampersands and non-Latin scripts can trip a security rule or break a path on a filesystem with a mismatched encoding. Renaming to plain lowercase letters, numbers and hyphens costs nothing and rules the branch out in seconds.