photo credit: Zenit via photopin (license)

Can’t remove images from the admin in Magento?

Today I stumbled upon an issue in Magento which I couldn’t wrap my head around: In the backend I checked an image to be removed from the media gallery, but upon saving, nothing happened. Magento didn’t show a message and my logs were empty.

Screen Shot 2015-03-03 at 16.44.11
After a while of looking what was going wrong, I finally found out what was causing the problem. So I hope this article might save someone out there the same frustration I had.

Multiple store views

The problem was that I had multiple store views in my shop, and one of those views had a slightly different configuration than the default configuration:

Screen Shot 2015-03-03 at 16.46.47
Resetting the checkboxes to ‘Use Default Value’ fixed the problem. Now I was able to remove this image (from the default store view).

What’s happening under the hood?

The reason for this feature is the afterSave() -method in Mage_Catalog_Model_Product_Attribute_Backend_Media . This method generates an array called $picturesInOtherStores which is exactly what it says it is: an array of images that are used in other store views. Now, the code that checks for removal is the first part of the foreach() -loop in the method:

As you can see, it checks if an image is flagged for removal but it also checks if the image is not used in a different store view. If so, it just ignores the remove-flag, but it also doesn’t give you any message whatsoever about why the image isn’t removed! Silly Magento…
So there you have it! That’s why your image isn’t removed from the backend in Magento. I hope this article saved you the time I spent on tracking down this ‘feature’.

Visitors give this article an average rating of 4.6 out of 5.

How would you rate this article?

17 thoughts on “Can’t remove images from the admin in Magento?”

  1. Nicola says:

    Hello, nice trick. I have the same problem when I try to delete all the product images from code. All images but one are removed. I haven’t yet found the way to do the same programmatically. Instead, following your topic, I was able finally to do directly from Magento backend. Regards,

    1. Nicola says:

      I solved overriding the method in a custom rewrite block, removing the following code:
      !isset($picturesInOtherStores[$image[‘file’]]), also if this change the default behavior from the backend (it was not my original purpose).


  2. Katya says:

    I sell items that are one-off products. So when they sell on the other site, I don’t need them to even remain in the Magento database. I need the server space or really the file count needs to stay low for their autobackup to run.

    So I’m deleting products and realize that it’s not helping me because deleting the product doesn’t delete the image. So for every product I remove, I’ll have to go delete the image via ftp. Oh joy.

  3. Rafasshop says:

    Thank you for share this post. I have the same issue related with one of the storeviews.

    Is there any sql sentence that can reset in all the storeviews the checkboxes to ?Use Default Value??

    Thank you!

    1. Giel Berkers says:

      Perhaps deleting all rows from catalog_product_entity_media_gallery_value where the store_id != 0?

      1. Rafasshop says:

        Thank you Giel! I understand that I need to replace the sotre_id=0 with the number of the stores that have images assigend different than “0”. I’m right? Thanks again.

        1. Giel Berkers says:

          Yes, store_id != 0 stands for all store id’s that don’t equal zero. But remember: cool kids always backup first! 😉

          1. Rafasshop says:

            oohh I understand! thank you so much Giel! Yes, I have very limited knowledge, for this reason I make all things first in staging server and I will make the mysql backup in live server too before changes 😀

  4. liufangjian001Danny says:

    Thanks for sharing this tips. I had the same problem, fixed by following your tip. Thank you again!

  5. chanikya says:


    when i am trying to delete product image from magento backend i got error decode syntax error even i have trying with store views also same error occurred.Can you please help me on this

    Error:Decoding failed: Syntax error


  6. pixeleightstudio says:

    This saved me with a client. THANK YOU!

  7. Carlos says:

    I was going to delete the product and import it again, thinking that was a problem with Magento and its DB, but fortunately I found your post.
    Thank you!!!

  8. tramnhadam@gmail.com says:

    so, how to edit that code to make Magento delete images in both database & FTP (when checked “Remove Image”)?

  9. Amand sinha says:

    Thanks Giel, Your post was very help full for me

  10. Thanks a lot Giel! This post was very helpful for me too.

  11. Koce says:

    Great information! Thank you, saved from my time. All the best!

Leave a Reply