Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

Bulk Delete Images
Dom Rand
May 1, 2015 - 11:13 am
Member Since: April 2, 2014
Forum Posts: 219
sp_UserOfflineSmall Offline

Hi Guys

Came across this the other day that I needed to delete in excess of 3000 images that were wrong size. Having uploaded via data flows I found this piece of code that will delete the images for you.

require_once ‘app/Mage.php’;

$products = Mage::getModel(‘catalog/product’)->getCollection()
->addAttributeToFilter(‘entity_id’, array(‘gt’ => 7902));

$mediaApi = Mage::getModel("catalog/product_attribute_media_api");

foreach($products as $product) {
$prodID = $product->getId();
$_product = Mage::getModel(‘catalog/product’)->load($prodID);
$items = $mediaApi->items($_product->getId());
if (count($items) > 0) {
foreach($items as $item) {
$mediaApi->remove($_product->getId(), $item[‘file’]);
echo $product->getId() . " done
} else {
echo $product->getId() . " has no images

with this code being your product id that you want to delete from

->addAttributeToFilter(‘entity_id’, array(‘gt’ => 7902));

Upload to your root file and open in browser. Delete after use.

I am not liable for deleting images using this method.

The following users say thank you to Dom Rand for this useful post:

Dave Furness

"Dont believe everything you read on the internet just because there is a picture with a quote next to it" Abraham Lincoln

Dave Furness

May 1, 2015 - 1:36 pm
Member Since: July 19, 2013
Forum Posts: 4606
sp_UserOfflineSmall Offline

Hey Dom,

Brilliant, thank you for sharing that could be really useful for some sellers!


Every expert was once a beginner


Not so New
May 27, 2015 - 2:32 pm
Member Since: May 5, 2015
Forum Posts: 8
sp_UserOfflineSmall Offline

Create a php at root direct of magento system
require_once “YOURMAGENTODIR/app/Mage.php”;

set current store is admin and set Developer mode

Get Product Collection

Remove image by using below code


Why Should You Join UnderstandingE?

  • Access to over 500 step-by-step video tutorials
  • +20 video courses available
  • Magento, M2E Pro, Magmi, eBay, Amazon & Design all covered
  • Everything is in 100% Plain English
  • Learn how to build your own multi-channel software for eBay & Amazon
  • Access to the community forums, meet fellow business owners like yourself

Join Now with 2 Clicks


Join now for less that £1 per day you can gain access to over 400 step-by-step video tutorials & learn how to build your very own multi-channel software.


Forum Timezone: Europe/London

Most Users Ever Online: 1012

Currently Online:
15 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Jim @ Moogento: 688

Steve Froggatt: 514

Badeth - UE: 513

Jimbob: 453

Paul Cartwright: 414

Forum Stats:

Groups: 6

Forums: 37

Topics: 5222

Posts: 27489

Administrators: Matthew Ogborne: 4565, Dave Furness: 4606