Solving WordPress unable to upload media – another way

Solving WordPress unable to upload media – another way

Working with WordPress installations all the time, I get to encounter the weirdest issues. One of theme is the all-known “unable to upload media”, translated by WordPress to a clear and yet useless message:

Unable to create directory wp-content/uploads/YEAR/MONTH.

Is its parent directory writable by the server?

 

First step is, naturally, to check permissions. All the folders (including wp-content, wp-content/uploads, wp-content/uploads/YEAR if exists should be owned or at least writable by the webserver user). This usually solved about 80% of the media upload failure cases.

But what do you do when permissions are perfect, and yet WordPress can’t upload? One direction is to find out if the WordPress installation is a new one or old. If it’s old, was it always on this particular server or has it moved around (among servers or even among hosting control panels)?

The hint in my case was that the account was transferred (together with WordPress) from Webmin to cPanel in the past year. And I was surprise to learn that WordPress stores the full media path in its database (which also includes the username). And we all know usernames change or are forced to certain length (like in cPanel).

wordpress-mysql-uploadpathBrowsing the database and the wp_options table I quickly found the culprit: the upload_path key was storing an invalid path (using the old account username).

After updating it to the correct (current) path, uploads returned to working order.

 

You should only edit the database if you are familiar with SQL. Otherwise ask a friend or your (friendly) server admin to help.

2 Comments

  1. You could have just updated it from within WordPress Admin under the Media Settings. But I appreciate the article, you helped me figure out where the issue was. Thanks!

    Dennis

Leave a Reply