How to Fix Image Upload Error in WordPress

Recently we published our Complete Guide to Fix WordPress Errors, and one of our readers emailed us and to find how to fix Image Upload Error in WordPress. Not such a long time that I can’t remember this error on my own blog that made me struggle the entire night and figure out the problem & fix it.

Well at that time my blog was just started so I didn’t post that solution, but its never too late to help others fixing this weird problem.

Basically, with this problem, you could not upload any image in WordPress, and if the upload goes through it will show images in the media library as broken. In this article, we will show you how to fix image upload issue in WordPress.

This is the reasons why you can face the WordPress Error Uploading Images.

  1. Image Size
  2. PHP Memory
  3. ModSecurity
  4. Plugin conflict
  5. File Permission
  6. PHP Version on Server

Disclosure: I may receive affiliate compensation for some of the links below at no cost to you if you decide to purchase a paid plan. You can read our affiliate disclosure in our privacy policy.

Image Size

This happens when you are trying to upload an image that is large in pixel size, for example, an image with 4000 x 3000 pixel. Which is too large for your server to process.

Some server shows an error even when your image is less than that size, it all depends on your server resources.

 

How-to-Fix-Image-Upload-Issue-in-WordPress

Solution

Decrease the image’s size. Don’t add a very large pixel image, for example. If your post content area is 800px wide, don’t add an image larger than that.

Reduce image size by trial and error until you are able to upload it without any error. 1075px is enough for a most WordPress site if you are using a premium WordPress theme check its documentation to know the image size required.

As it won’t have enough room to expand and all it do is shrink up to that space, the problem is that while uploading that size of the image the WordPress will consume a huge amount of memory. Since some server limits the amount of memory that can be consumed by a WordPress, in this case, it will cause an error while uploading.

 

PHP Memory

WordPress functionality and resources can be limited after all it runs on PHP and the servers running PHP can limit this resources.

You can increase your PHP memory either by all yourself or ask your web hosting support team. The memory can be increased in 2 ways:

Solution

  • Increase WordPress Memory
  • Increase PHP Memory

 

Increase-Memory-Limit

You can increase the WordPress memory by adding this code in your wp-config.php which is located in your WordPress root directory.

 define('WP_MEMORY_LIMIT', '256M'); 

This above setting may not work if your host/server does not allow you to increase the PHP memory limit or limits it to some extent, so I suggest talking to your support directly and ask them to change the limit for you. You’ll skip the hassle. Its better ask the support team to increase your PHP memory, but if you love the hassles then add this below code to your php.in or php5.ini

memory_limit 256M

 

ModSecurity

You may have never noticed this security or you know about this. ModSecurity is also known as .htaccess and I hope you have seen this file in your WordPress root directory, mostly it’s hidden.

If your server has mod security enabled then may be in your case this file is causing the problem.

Solution

You need to disable the mod security for your upload so create a .htaccess inside the wp-admin folder and add the following codes.

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

That will disable mod_security for the upload file receiving code in the wp-admin.
Note: Remove this if it’s causing any error on your server.

 

 

Plugin Conflict

It has been confirmed that in major of the cases a plugin has been conflicting with the upload process. In many cases, even my blog has suffered from plugin conflicts.

it’s due to some outdated plugin or some syntax error that was triggered due to upgrading to latest version of one or other plugin or the WordPress.

 

image-upload-issue

I have found that plugins that help in uploading, shrinking or compressing images mostly case the error. In some cases, some desktop application had also triggered this error if you use that app to compress or render images.

Also, jetpack, plugins that help upload to cdn or aws or remote servers causes WordPress error on uploading images.

Solution

Please proceed to disable one plugin at a time. Clear your cache and browser history and revisit media uploader to upload your image and see if you are successful.

If not try not to use any WordPress plugin and desktop apps and upload a raw .png or .jpg and check whether it works or not.

 

File Permission

If its not a plugin or a limited memory that causing the error while uploading the images then I would suggest you have a look at the file permission on your server.

File permission can change automatically even if you didn’t change it.

Want to know. How did it change?

If you hosting company run an upgrade on their servers or a plugin has been updated by you then the file permissions can be changed.

If you are using a shared web hosting then the possibility is that a hacker has accessed your files and your file permission may have been changed by a payload that the hacker may have uploaded.

 

ftp-file-permissions

You can change the file permission easily via an FTP program, I use Cyberduck for ftp on both my mac and windows pc.

Access your files through FTP and then go to /wp-content/ directory. There you will see /uploads/ folder. Right-click on the uploads directory and select file permissions.

At first, you will need to set file permissions for uploads directory itself and all the subdirectories inside it to 744. To do that, enter 744 in the numeric value box, and then check the box next to Recurse into subdirectories.

Lastly, you need to click on ‘Apply to directories only’ radio button. Click on the OK button to apply these changes.

 

directories-file-permissions

You need to repeat the same process but for the uploads folder.

You will need to set file permissions for all the files in the uploads directory. To do that, right click on uploads directory and select file permissions.

In the file permissions, dialog box changes the numeric value to 644. Check the box next to Recurse into subdirectories. Click on Apply to files only radio button. Click on the OK button to apply these changes.

Your FTP program will apply this changes and your image uploader will work again

 

PHP Version on server

It remains unnoticed throughout the entire task you do while solving this error, As in most of the cases no one think about this.

Why should anyone, as in most cases the users say it was working till yesterday before I hit that update button?

But updating the plugin, theme or WordPress can trigger this error and several other errors, as WordPress is built upon PHP and it has some standards to follow, so the developer always stats the version which is stable for WordPress.

If your server PHP version is not the same as required by the WordPress, then contact your server support staff and ask them to make the changes of your PHP version to the requirement of WordPress.

 

Conclusion

(Update). This fix was pointed out by a couple of our readers. We thank them for that!

Make sure you don’t have an apostrophe in the image file’s name (e.g. john‘s-blogging.png), because that will trigger the error as well.

(Update). If you’re using an image optimizer plugin, deactivate the plugin and see if that solves the issue.

If you are still facing the problem, then let me know. I will be happy to help you 🙂 And comment below which method worked for you to fix this error.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *