Image upload failures in WordPress 3.1

Playing with wordpress (this blog engine) I got into a mess of images uploading. To my surprise 1 of 6 images I tried to load failed leaving blank space in loading panel right after “Crunching…” message. I took a look into upload directory and the file was loaded, but rescaled image versions were absent. What is more, the single image was loaded to file system but was not registed in DB and effectively was unavailable in media library. I could repeat the problem even after renaming the problematic file, after rescaling in Picasa and so on.Investigation was not trivial, especially I am not PHP expert, wordpress is running on lighttpd instead of Apache, and the OpenWRT environment itself is rather humble with diagnostic tools – I could not effectively turn on logging with any relevant information. Anyway, I do not want to bore you to death with all details of 4 hours of chasing the ghost. Let me just share with what I tried:

  • disabling SSL configuration for administrative part, including plugin for non-ssl-uploads,
  • turning off php-fcgi (fast cgi) to spawn php-cgi subprocesses per-request,
  • enabling debug mode of wordpress for some messages,
  • comparing and diagnosing requests with firebug in firefox,
  • disabling thumbnails generation by GD library

None of them worked. At last I found some discussion about corrupted JPG data that PHP libraries are vulnerable to. It is not even about GD which was disabled when wordpress failed on upload. To my another surprise, converting corrupted JPG into other format, PNG for instance, and then back to JPG again solved the problem. The problem with JPG is so deep that requires building it from scratch: attempt to save again JPG after corrections/rescaling/image quality changes… simply does not work.

I experimented with all files in conversion process. The list of loaded files was like that:

… and the result after processing all of them looked like this:

Blank space is remainder of “corrupted.jpg”. PNG version was successfully loaded same as fixed version of corrupted JPG. Good news is I solved the problem. Bad news is you have to manually clean up upload directory from partially processed corrupted JPG. I would say PHP sucks, but actually I am fine, it is Web2.0 property, where hacking to solve is best practice…

This entry was posted in WordPress. Bookmark the permalink.

Leave a Reply

Your email address will not be published.