Is there a way to delete all images for products that are set as disabled?

It's just a lot of my products that are disabled are taking my storage space up on my server.

I'd just like to be able to cron a PHP script every week or so however I'm unsure what this script might actually look like?

Any idea if this is possible?

1 Answer 1


//This method will work if you hit the file on root. There can be many rectifications for this. But please make sure to take proper backup before running this
error_reporting(E_ALL ^ E_NOTICE);

require_once 'app/Mage.php';

$products = Mage::getModel('catalog/product')->getCollection()

foreach($products as $product) {

$id = $product->getId();
$product = Mage::getModel('catalog/product')->load($id);
$mediaGalleryAttribute = Mage::getModel('catalog/resource_eav_attribute')->loadByCode($entityTypeId, 'media_gallery');
$gallery = $product->getMediaGalleryImages();
foreach ($gallery as $image)
    $mediaGalleryAttribute->getBackend()->removeImage($product, $image->getFile());


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.