WordPress media upload fails with "Unexpected response from the server"
Unexpected 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The upload request returns 413 Request Entity Too Large in the browser network tabnginx rejects the request body as too largeFix - 2
The 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
Small 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
- 1
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 nginxConfirmed by nginx.org
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 = 256M3Verify
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
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 -u2Fix
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 | headConfirmed by developer.wordpress.org
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- stegnor.comMy company site: 804 pages from a Python and Jinja generator, with 15 free browser tools.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
wp-admin loads a completely blank page in WordPress
Allowed memory size of xxxxxx bytes exhausted
A blank wp-admin is a PHP or database error that is hidden.
4 causes, each with a fixWeb apps
Fonts on another domain are blocked by CORS (nginx and Apache)
Reason: CORS header 'Access-Control-Allow-Origin' missing
Fonts loaded with @font-face from another origin are fetched with CORS, so the font server must send Access-Control-Allow-Origin.
4 causes, each with a fixWeb 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 fixWeb apps
CodeIgniter 3 shows 'The action you have requested is not allowed.'
403 Forbidden
With csrf_protection on, CodeIgniter 3 compares the POST token with the CSRF cookie and returns this 403 when either is missing or they differ.
4 causes, each with a fixWeb 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 fixWeb apps
npm start runs, but the browser does not refresh when you save a file
Saving a file does nothing while npm start is running
The watcher behind npm start is not seeing your edit.
4 causes, each with a fix