Last active
August 29, 2015 14:10
-
-
Save ryaan-anthony/9c3ffc3d75dc9c754f3d to your computer and use it in GitHub Desktop.
Magento - remove broken images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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