Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

WordPress media upload fails with "Unexpected response from the server"

ErrorUnexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.

Short answer

WordPress shows this message when the upload request did not come back as the JSON it expects. The real reason sits one layer below: nginx rejected the body as too large, PHP dropped the whole request for exceeding post_max_size, or the uploads folder is not writable. Check the browser network response and the server logs first.

  • Applies to WordPress 6.8, PHP 8.3, nginx 1.26, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Reproduce the upload with the browser's network tab open and look at the status code of the upload-async or media request, then read the web server error log for the same minute.

    sudo tail -n 30 /var/log/nginx/error.log
    php -i | grep -E "upload_max_filesize|post_max_size"
  2. 2Match what you see, then jump to its fix

    1. 1The upload request returns 413 Request Entity Too Large in the browser network tabnginx rejects the request body as too largeFix
    2. 2The request reaches PHP but the file never arrives; PHP defaults are 2M for a file and 8M for the whole postThe file is bigger than PHP's upload limitsFix
    3. 3Small files fail too, and the PHP or web server log mentions a failed write or permission denied under wp-content/uploadsThe uploads folder is not writable by the web server userFix

What does the error look like?

  • Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.
  • 413 Request Entity Too Large

Cause 1 of 3

nginx rejects the request body as too large

1Check

nginx allows a 1 MB request body by default. The docs add that browsers cannot show a 413 properly, which is why WordPress only reports an unexpected response.

grep -R "client_max_body_size" /etc/nginx/

2Fix

Raise the limit in the server block of the site, to a size above the biggest file you accept, then reload nginx.

server {
    client_max_body_size 64m;
}

3Verify

Test the config, reload, and upload the same file again.

sudo nginx -t && sudo systemctl reload nginx

Confirmed by nginx.org

Did this fix it?

Cause 2 of 3

The file is bigger than PHP's upload limits

1Check

upload_max_filesize caps one file, and post_max_size caps the whole request. When the post exceeds post_max_size, PHP leaves $_POST and $_FILES empty, with no error for the file.

php -i | grep -E "upload_max_filesize|post_max_size|memory_limit"
php -i | grep "Loaded Configuration File"

2Fix

Set post_max_size larger than upload_max_filesize, and memory_limit larger than post_max_size, in the php.ini that PHP-FPM or Apache loads (the CLI may read a different file). Restart the service.

; php.ini
upload_max_filesize = 64M
post_max_size = 72M
memory_limit = 256M

3Verify

Restart PHP-FPM, then run the check command again.

sudo systemctl restart php8.3-fpm
php -i | grep -E "upload_max_filesize|post_max_size"

Confirmed by php.net

Did this fix it?

Cause 3 of 3

The uploads folder is not writable by the web server user

1Check

WordPress writes into wp-content/uploads as the account PHP runs as. Compare the folder's owner with that account.

ls -ld wp-content/uploads
ps -o user= -C php-fpm8.3 | sort -u

2Fix

Give the folder to the account PHP runs as. The WordPress guide says files WordPress must write to should be owned by that account, and warns against 777.

sudo chown -R www-data:www-data wp-content/uploads
sudo find wp-content/uploads -type d -exec chmod 755 {} \;

3Verify

Upload a small image and check that it lands in the Media Library.

ls -l wp-content/uploads | head

Confirmed by developer.wordpress.org

Did this fix it?

How do I stop it coming back?

  • Set the nginx and PHP limits together; a raised PHP limit does nothing while nginx still stops the body at 1 MB.
  • Keep upload size limits as small as your real files need.
  • Keep wp-content/uploads owned by the PHP user and never open it with 777.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

OpenAPI does not work in an ASP.NET Core minimal API

404 Not Found at /openapi/v1.json

ASP.NET Core 9 and later generate OpenAPI documents with the Microsoft.AspNetCore.OpenApi package: AddOpenApi registers it and MapOpenApi serves /openapi/v1.json.

3 causes, each with a fix

Web apps

The browser blocks your API response: no Access-Control-Allow-Origin header

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/orders. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

The browser received the response but refused to hand it to your script, because it did not carry an Access-Control-Allow-Origin header naming the page's origin.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.