Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento - remove broken images
<?php
include_once("app/Mage.php");
umask(0);
Mage::app('admin');
$collection = Mage::getResourceModel('catalog/product_collection');
foreach ($collection as $product){
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$items = $mediaApi->items($product->getId());
foreach($items as $item){
$image_url = Mage::getBaseDir('media').'/catalog/product'.$item['file'];
if(!file_exists($image_url)){
$mediaApi->remove($product->getId(), $item['file']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.