Skip to content

"HTTP error" when uploading images to the WordPress media library

The WordPress media library shows a bare HTTP error when an image upload fails, because the uploader has no idea what went wrong. Read the real error out of the async-upload.php response, then work through PHP limits, Imagick memory, uploads permissions and ModSecurity in order of frequency.

HTTP error. is not a diagnosis. It is the fallback string the media library’s JavaScript uploader prints whenever /wp-admin/async-upload.php returns anything other than the JSON it expected. A PHP fatal error, a truncated response, a firewall block page, a gateway timeout and an empty body all collapse into the same two words. So the first move is not to start raising limits at random — it is to open the browser’s Network tab, read the actual response body for that request, and turn the placeholder back into a real error. Once you can see it, the cause is almost always one of six things, and they sort cleanly by how often they turn up.

What you’ll accomplish

  • Recover the real error hiding behind HTTP error. from the async-upload.php response body, the PHP error log and debug.log.
  • Read the effective limits your site is actually running with, instead of guessing from a php.ini you may not be using.
  • Tell PHP size and time limits apart from memory exhaustion during resizing, from filesystem permissions, and from a WAF or reverse proxy rejecting the request.
  • Apply the fix at the correct layer, whether you are on shared hosting or a server you administer.
  • Confirm the repair by re-uploading the file that failed and checking that every intermediate size was written to disk.

Prerequisites

  • Administrator access to the WordPress site, and a browser with developer tools.
  • Some idea of where your site runs, because the fix path forks hard here. On shared or cPanel hosting you will do almost everything through the control panel: MultiPHP INI Editor for PHP directives, Tools → Site Health → Info for the effective values, ModSecurity Tools in WHM if the host exposes it, and a support ticket for anything at the web-server or proxy layer. On a server you control, the same changes live in php.ini or a PHP-FPM pool file, the Nginx or Apache vhost, and ImageMagick’s policy.xml.
  • Root or sudo is required for exactly three things below: reloading PHP-FPM after a pool or php.ini change, editing web-server or ImageMagick configuration, and reading /var/log. Everything else works from the WordPress admin or an unprivileged SSH account, and the diagnostic half of this guide is what turns a vague ticket into one your host can act on in a single reply.
  • WP-CLI is used for the read-only checks; each has a Site Health equivalent. Take a backup before editing wp-config.php.

How it works

An upload from the media library is not one request doing one thing. It is a single POST that passes through five owners in sequence, and any of them can end it.

Five-stage diagram of a WordPress media upload — browser Plupload POST to async-upload.php, PHP request intake against upload_max_filesize and post_max_size, wp_handle_upload writing into wp-content/uploads, the Imagick or GD image editor generating intermediate sizes, and the JSON response — with the failure mode annotated beside each stage

The browser’s Plupload component POSTs the file as multipart/form-data. Before PHP sees a single byte, the web server can reject the body for being too large. If it gets through, PHP enforces upload_max_filesize on the file and post_max_size on the whole request, and max_input_time on how long it will wait to receive it. Only then does WordPress call wp_handle_upload(), which checks the MIME type against the allowed list and moves the temporary file into wp-content/uploads/.

That is where most people stop reading, and it is exactly where the interesting failures start. After the original is stored, WordPress hands it to an image editor — WP_Image_Editor_Imagick if the extension is present, WP_Image_Editor_GD otherwise — and asks it to generate every registered intermediate size. Decoding a 24-megapixel JPEG into an uncompressed bitmap costs far more memory than the file size suggests: roughly width times height times four bytes, so a 6000x4000 image needs about 96 MB before any resizing happens. On a 128 MB memory_limit shared with the rest of WordPress, that is the whole budget. PHP dies mid-request, the response body is a fatal error or nothing at all, and the uploader says HTTP error.

The same message covers all of this for a structural reason: the uploader only checks whether it got parseable JSON back. Everything else is noise to it. Your job is to go and read the noise.

Step-by-step

1. Read the response body before you change anything. Open the media library, start the browser’s developer tools on the Network tab, and reproduce the failure. Find the async-upload.php request — it will be the one with a non-200 status, or a 200 with a body that is not JSON — and open its Response tab. This single step decides everything that follows.

You are looking for one of these shapes:

HTTP/1.1 413 Request Entity Too Large      → web server body limit
HTTP/1.1 403 Forbidden  (HTML block page)  → ModSecurity or a WAF rule
HTTP/1.1 504 Gateway Time-out              → PHP took longer than the proxy waits
HTTP/1.1 500  Fatal error: Allowed memory  → memory exhaustion while resizing
HTTP/1.1 200  (empty body)                 → PHP crashed without writing output

2. Turn on the WordPress debug log. If the response body was empty or unhelpful, make WordPress write its own record. Add these to wp-config.php above the “stop editing” comment:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Then reproduce the upload and watch the file:

tail -n 40 wp-content/debug.log

A memory failure looks unmistakable:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 98304040 bytes) in /var/www/html/wp-includes/class-wp-image-editor-imagick.php on line 200

Turn WP_DEBUG back off when you are finished. Leaving it on in production is its own incident.

3. Check the PHP error log too. debug.log only captures what PHP manages to write through WordPress. A segfault or an OOM kill will not appear there.

sudo tail -n 50 /var/log/php8.2-fpm.log
WARNING: [pool www] child 2841 exited on signal 9 (SIGKILL) after 12.4 seconds from start

That signal 9 is the kernel’s OOM killer, not PHP’s memory_limit — a different fix, covered in step 7. On cPanel, the equivalent lives in ~/logs/ or the Errors page in the control panel.

4. Read the effective limits instead of guessing them. The php.ini you find first is very often not the one serving your site. Ask WordPress what it actually sees:

wp eval 'echo size_format( wp_max_upload_size() ), "\n";'
64 MB

wp_max_upload_size() returns the smaller of upload_max_filesize and post_max_size, which is the number that genuinely governs uploads. For the individual directives:

wp eval 'foreach ( array( "upload_max_filesize", "post_max_size", "max_execution_time", "max_input_time", "memory_limit" ) as $k ) { printf( "%-20s %s\n", $k, ini_get( $k ) ); }'
upload_max_filesize  64M
post_max_size        64M
max_execution_time   30
max_input_time       60
memory_limit         256M

One caveat: WP-CLI runs under the CLI SAPI, which can load a different ini file than PHP-FPM does. If the numbers look suspiciously generous, cross-check under Tools → Site Health → Info → Server, which reports the web SAPI’s values — and which is also the no-shell, no-root answer to this whole step. Now compare those numbers to the file you tried to upload. If the file is 78 MB and the limit is 64 MB, you are done diagnosing.

5. Match what you observed to a cause. With the response body in hand and the limits read, the pattern of which files fail narrows it further.

Decision tree starting from the bare HTTP error message, through reading the async-upload.php response body, into four observed patterns — fails only above a size, fails for every file, fails only for large-dimension images, fails only for certain file types — each mapped to a likely cause and a first corrective move

6. Raise the size and time limits at the layer that owns them. If step 4 showed the limits are the problem, change them where PHP will actually read them. On a server you control, in /etc/php/8.2/fpm/php.ini or better a pool override:

upload_max_filesize = 128M
post_max_size = 132M
max_execution_time = 300
max_input_time = 300
memory_limit = 512M

Keep post_max_size slightly above upload_max_filesize; the POST carries form fields and nonces on top of the file itself. Then reload and confirm the new value took:

sudo systemctl reload php8.2-fpm && wp eval 'echo size_format( wp_max_upload_size() ), "\n";'
128 MB

On shared or cPanel hosting, the same directives live in MultiPHP INI Editor, and no restart is needed. Note that php_value lines in .htaccess are silently ignored when PHP runs as FPM or CGI rather than as an Apache module — a very common reason a “fix” appears to do nothing.

7. Confirm which image editor is running, and give it room. If small files upload but large-dimension ones fail, this is your stage.

wp eval 'echo get_class( wp_get_image_editor( ABSPATH . "wp-includes/images/media/default.png" ) ), "\n";'
WP_Image_Editor_Imagick

If that returns WP_Image_Editor_GD, Imagick is missing or disabled — GD is functional but hungrier and less capable with some formats. Check what is loaded:

php -m | grep -iE 'imagick|^gd$'
gd
imagick

ImageMagick also enforces its own resource ceilings, entirely separate from PHP’s, and a low memory or area policy will kill large images no matter what memory_limit says. This needs root to inspect and change:

grep -E 'memory|map|area|width|height' /etc/ImageMagick-6/policy.xml
  <policy domain="resource" name="memory" value="256MiB"/>
  <policy domain="resource" name="area" value="128MP"/>

Finally, stop the problem at the source by capping how large an original WordPress keeps. The big_image_size_threshold filter controls the dimension above which WordPress stores a -scaled version and uses that for everything downstream; the default is 2560 pixels:

add_filter( 'big_image_size_threshold', function () {
	return 1920;
} );

8. Check ownership and permissions on the uploads directory. If every upload fails, including a 40 KB PNG, look here before anything else.

stat -c '%U:%G %a %n' wp-content/uploads
ps -eo user,comm | grep -E 'php-fpm|apache2|httpd|lsphp' | sort -u
www-data:www-data 755 wp-content/uploads
www-data         php-fpm8.2

The owner of uploads must match the user PHP runs as. A mismatch after a manual file move or a restore from backup is one of the most common causes of a universal upload failure. Fix ownership rather than reaching for chmod 777, which solves nothing here and creates a real problem — the reasoning is in WordPress file permissions hardening. Also confirm you have not run out of disk or inodes, which produces identical symptoms:

df -h . && df -i .

9. Look for a ModSecurity or WAF rule rejecting the request. A 403 with an HTML body in step 1 points straight here. On a server you administer:

sudo grep -F 'async-upload.php' /var/log/apache2/modsec_audit.log | tail -n 5
[id "949110"] Inbound Anomaly Score Exceeded (Total Score: 10) ... "/wp-admin/async-upload.php"

Take the rule ID from that line and exclude it for that one endpoint only, never globally:

<LocationMatch "/wp-admin/async-upload\.php">
    SecRuleRemoveById 949110
</LocationMatch>

On cPanel, WHM → ModSecurity Tools → Hits List shows the same information without a shell, and lets you disable a rule per-account. If the block is happening at a CDN or managed WAF rather than on the origin, this is a policy change the account owner has to make — see the last section.

10. Raise the body size and timeout limits on the reverse proxy. A 413 or 504 in step 1 belongs here, and no amount of PHP tuning will touch it. Nginx defaults to a 1 MB request body:

client_max_body_size 128m;
fastcgi_read_timeout 300s;

Apache uses LimitRequestBody, and if it proxies to PHP-FPM, ProxyTimeout. Whatever you set, keep the proxy timeout above PHP’s max_execution_time and above PHP-FPM’s request_terminate_timeout — if the proxy gives up first, PHP finishes the work successfully and the browser still shows HTTP error.

Validate it works

Re-upload the exact file that failed. A successful async-upload.php request returns HTTP 200 with a JSON body whose success key is true and which carries the new attachment ID. Then confirm every intermediate size was actually written, rather than trusting the green checkmark:

wp post meta get 178 _wp_attachment_metadata --format=json | head -c 400
{"width":5472,"height":3648,"file":"2026\/08\/lobby-scaled.jpg","sizes":{"thumbnail":{...},"medium":{...},"medium_large":{...},"large":{...}}

The sizes array must contain every size your theme registers. If it is short, resizing partially failed and you are still short on memory or time. Cross-check on disk:

ls -1 wp-content/uploads/2026/08/ | grep lobby
lobby-150x150.jpg
lobby-300x200.jpg
lobby-768x512.jpg
lobby-1024x683.jpg
lobby-scaled.jpg
lobby.jpg

If earlier uploads went through with sizes missing, repair them in bulk:

wp media regenerate --only-missing --yes

Then upload one more file close to your new limit; a fix that works at 2 MB and fails at 100 MB has only moved the boundary. Finish by checking the front end — auditing lazy loading and srcset on WordPress media covers what should appear in the markup once the size set is complete again.

Troubleshooting

You raised the limits and nothing changed. Either the change landed in an ini file the web SAPI never reads, or PHP-FPM was not reloaded, or you edited .htaccess under a setup that ignores php_value. Re-run the step 4 check through Site Health, not WP-CLI, and believe that number over the file you edited.

The upload succeeds but the image is broken or zero bytes. PHP’s temporary upload directory is unwritable or falls outside open_basedir. WordPress reports this as Missing a temporary folder. Check upload_tmp_dir and that the path exists and is writable by the PHP user.

It works for administrators and fails for editors. Not a limits problem. A security plugin or a upload_mimes filter is restricting types by role, or a role’s capabilities were edited. Test with the same file, same browser, two accounts, and compare the response bodies — they will differ.

Failures are intermittent, and the site sits behind a load balancer. If wp-content/uploads is on each node’s local disk instead of shared storage, roughly half the uploads land on a node the next request does not hit — the uploader may even succeed while the image 404s. That is a storage architecture fix, not a PHP one.

Everything is fine at the origin and fails through the CDN. Resolve the hostname directly to the origin IP in your hosts file and upload again. If it works, the body limit or WAF rule belongs to the CDN.

When this is the wrong approach

Sometimes the honest answer is that the file should never have been uploaded at that size. A 45-megapixel phone photo does not need to reach the media library intact: WordPress stores a -scaled copy and serves resized derivatives regardless, so the full-resolution original mainly consumes memory during the one request that decodes it and disk space forever after. If editors upload straight off a camera, resizing to about 2560 pixels on the long edge first removes this entire class of failure. Raising memory_limit to 1 GB so one upload can succeed is a workaround for an editorial habit.

The other case is when the block is not yours to lift. If a managed WAF, a corporate proxy or a CDN security policy is rejecting async-upload.php, tuning PHP on the origin achieves nothing. Take the request ID from the block page to whoever owns that policy and ask for a scoped exception. The same applies on shared hosting where the host caps memory_limit below what your image sizes need — no configuration you are permitted to write will change that, and the real decision is about the hosting plan, not the code. And if uploads only fail during traffic peaks, the limits are not the cause; PHP workers are, which is a capacity question rather than this one.

Worth keeping open while you work: the wp_handle_upload() reference for exactly what WordPress validates and in what order, and the common WordPress errors page for the wider family of messages this one belongs to.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under enterprise WordPress operations; book an infrastructure consult.