Question

In the media tab, upload of a valid image file results in display of "HTTP error".

Reload of the media tab shows that the image did upload and resize, though.

Browser debug tools show that on upload, browser is making a POST to wp-admin/async-upload.php. The server responds with a 500 error. The body of the response, though, is suspicious. The first part is a JSON structure. The JSON structure is immediately followed by an HTML document with the title "Wordpress Error" but an empty body.

Nothing going into the webserver (apache) error log and WP debug mode and increased PHP error/warning verbosity has not been helpful. Disabling all plugins had no effect on the error. Tried switching between GD and ImageMagick also with no success.

Relevant software versions:

  • Wordpress 4.2.2.
  • PHP 5.5.12-2ubuntu4.4.
  • Ubuntu Utopic

Any ideas on what might cause async-upload.php to return both JSON and an HTML error document and/or how I might further debug this?

Was it helpful?

Solution

I had the same issue and did not find any information in my debug output.

It worked out, that DOING_AJAX was not defined (I don't know why).

Changing the beginning of async-upload.php from

if ( isset( $_REQUEST['action'] ) && 'upload-attachment' === $_REQUEST['action'] ) {
    define( 'DOING_AJAX', true );
}

to

define( 'DOING_AJAX', true );

worked for me. Maybe I will have a deeper look and find the real root cause.

OTHER TIPS

This likely isn't exactly an issue caused by WordPress, but due to server configurations and/or settings. 500 errors are pretty generic and can have a variety of origins, so it is hard to give the one directive that will solve it. By the way, the returning of JSON and HTML seems to be common when this happens, not sure where and it gets mixed up, might be here . I'm fairly certain this happens due to some memory issue.

Although it likely has to do with the memory, I can't know for sure, because there isn't enough information available to be 100% certain. So here is a little, not necessarily comprehensive, check list for you to process:

  • memory limit - your PHP memory might be just on the verge of being not enough, increase it; put define( 'WP_MEMORY_LIMIT', '128MB' ); into wp-config.php
  • .htaccess - corruption/issue; check it; possibly back it up and regenerate it
  • PHP5 - some hosts had problems with that, although I haven't seen it some time; try putting AddType x-mapp-php5 .php into your .htaccess
  • file permissions - make sure they are correct, if you are unsure, then re-set them up with the correct ones; codex article: changing file permissions
  • folder permissions --
    • WP - check an if needed correct them; codex article: changing file permissions
    • server - sometimes there are e.g. problems with the permissions of the temporary upload folder
  • re-uploading WP core files - although that shouldn't be necessary if the last two steps are done correctly, but sometimes there are other corruptions, so it might be an additional step to take
  • apache setup - make sure your apache is set up correctly on your server, so to your needs and actual requirements; e.g. one common culprit seems to be mod_security
  • check WP custom code - so what you wrote or been installing via plug-ins; you know the routine, test by deactivating and/or switching to default theme and so on

All the list items are pretty much well known and documented, so you will, if needed, find more information out there.

Last but not least, much success!

In the wp-config.php file (wordpress's root folder) you have to enable the debug.

You have to set wp_debug to true.

Change define('WP_DEBUG', false); to define('WP_DEBUG', true);

Save the file and refresh the browser (I suggest you to use ctrl+f5).

You'll see all the errors.

Im my case (WP v5.0), it was PHP version problem (PHP v5.4). Switching to PHP v7.2 solved this problem.

I suggest checking the webserver's error log before poking around in the dark.

In my case I found the following error message

2020/01/16 15:30:24 [error] 24844#24844: *206729 client intended to send too large body: 33962282 bytes, client: xxx.xxxx.xxx.xxx, server: example.com, request: "POST /wp-admin/async-upload.php HTTP/2.0", host: "example.com", referrer: "https://example.com/"

Which simply means that nginx' client_max_body_size was too low. WordPress only checks upload_max_filesize in php configuration so WordPress allows to upload larger files than client_max_body_size if that value is lower than upload_max_filesize.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top