Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryaan-anthony/9c3ffc3d75dc9c754f3d to your computer and use it in GitHub Desktop.
Save ryaan-anthony/9c3ffc3d75dc9c754f3d to your computer and use it in GitHub Desktop.
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