Has this ever happened to you? You find the perfect image for your WordPress post or page, but when you try to upload the image, you get an error. Worse yet, when you go to your WordPress Media Library, none of your previously uploaded images are visible!
Image upload errors are actually one of the most common issues faced by WordPress users. But in most cases, it’s an easy fix.
In this tutorial, I will show you how to do it yourself. I’ll also explain some of the reasons why it may happen, and how to prevent it from happening again.
WordPress image upload errors are frustrating when you haven’t experienced them before. You haven’t changed your workflow, yet the errors seem to appear out of nowhere.
Let’s look at why that could happen.
The Cause of Image Upload Errors in WordPress
In most cases, image upload errors in WordPress are the result of file permissions being set incorrectly. The errors give you a clue:
“Unable to create directory wp-content/uploads/2019/04. Is its parent directory writable by the server?”
“The uploaded file could not be moved to wp-content/uploads/2019/04.”
The “Unable to create directory” and “uploaded file could not be moved” errors indicate directory permissions problems.
As do broken images in the media library:
Now that we know what the problem is, how did it happen?
How Did the WordPress File Permissions Change?
Let’s assume you didn’t inadvertently change the permissions yourself (hey, we’ve all done it at some point). There are a couple of reasons why these could have changed: either installation of a plugin or third-party application or some kind of server upgrades or maintenance performed by your website host.
Highly rated and up-to-date plugins will rarely be the cause of permissions changes in your WordPress file structure. However, it’s been known to happen.
If you installed a plugin before the image problem began, you may want to disable it before you perform the fix outlined in this article.
Your website host is another probable cause of the problem. Server upgrades or maintenance can cause file permission changes. A restoration from backups or any number of other things done by the host, can do this as well.
Whatever the cause, the first thing we want to do is set the correct file permissions. This should fix any WordPress image upload issues.
Repairing WordPress File Permissions
FTP into your WordPress installation and open up the /wp-content directory.
Check the permissions on the /upload directory. If they are not 755, this is where we’ll make our fix.
Note: If the /upload permissions are correct, go into the /uploads directory and check permissions on the dated directories. Keep drilling down until you find the directory with incorrect permissions.
It’s unlikely that only the /upload directory would be affected if the issue was due to a server error or upgrade. For the purposes of this tutorial, we’re addressing only the /upload directory.
The steps we’re going to take to fix the problem may seem like a bit of a backward approach but bear with me. If you have a lot of images in a lot of directories, this is the easiest, quickest way to set everything right.
Our ultimate goal is to have permissions of 755 on the directories, and 644 on the image files. So the first thing we’re going to do is set everything, which includes files and directories, to 644. Here’s how you do it.
Right-click the “uploads” directory, then click the “File permissions…” link. If you’re using a MAC, you can hold down CMD+Click to launch the options list.
Depending on your FTP client, you’ll set either a numerical value of 644 or the written value drw-r–r–
We’re also going to set “Recurse into subdirectories.” This is because we want to apply this change to all the directories under /upload. Also select “Apply to all files and directories” because we want to change permissions on all the image files in the directories as well.
Click the “Okay” button.
At this point, you may notice that something didn’t happen quite the way you expected it to.
Depending on your host’s rules or server configuration, you may not be able to change a directory to 644. That restriction is in place so you don’t accidentally remove the execute permissions for the directory owner, which would effectively remove the directory from your website.
But if that happens, it’s okay, because we don’t want the directory permissions to be 644 anyway.
If you click down to the actual image files, they should all be 644, as we expected.
Now to fix those directory permissions, right-click the “uploads” directory and click the “File permissions…” link.
This time we’re going to set a numerical value of 755, or the written value drwxr-xr-x
We’re still going to set “Recurse into subdirectories,” but this time select “Apply to directories only.” This is because we do not want to change the permissions that we just set for all of the image files.
Click the “Okay” button.
If you check file permissions now, all directories should be 755 and the image files 644.
When you log in to your WordPress admin area, your Media Library images should be visible now and any new media uploads should proceed without any problems.
Preventing WordPress File Permission Problems in the Future
As far as preventing the problem from occurring in the future, it’s probably an impossibility depending on the problem.
It would be great if there was a single thing we could identify and change that would prevent file permissions from ever being set to incorrect values again, but there really isn’t.
If you determine the cause was a plugin or third-party application, it’s easy enough to avoid using that particular tool. You may even want to set up a test WordPress installation or a development environment so you are free to experiment and make mistakes without causing problems on your live WordPress website.
If the problem was caused by the host, that’s not really something you can prevent from happening again. That is, outside of letting them know it happened. If they aren’t responsive, perhaps finding a new host would be a better alternative.
Have you ever run into the problem of changing file permissions? Do you use a test installation or development environment for your WordPress changes and updates?
Author: Michael Phillips
Michael Phillips is a web hosting industry veteran, helping people make the most of their web presence since 1995.