Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find missing or not readable product image files in Magento1.
<?php
/**
* Find missing or not readable product image files in Magento1.
* Run this file via command line ( php fmpif.php ) or open it in your web browser.
*
* @copyright Copyright (c) 2016 Tobias Forkel (http://www.tobiasforkel.de)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
require_once 'app/Mage.php';
Mage::app();
// Collection of all products
$products = Mage::getModel('catalog/product')->getCollection();
// Get absolute path to media folder
$media = Mage::getBaseDir('media');
// Count missing files
$i = 0;
foreach ($products as $_product)
{
$product = Mage::getModel('catalog/product')->load($_product->getId());
foreach ($product->getMediaGalleryImages() as $image)
{
$file = $media . '/catalog/product' . $image['file'];
if (!is_readable($file))
{
$i++;
echo sprintf('The image file (%s) from product SKU number (%s) doesn\'t exists or is not readable.', $file, $_product->getSku());
}
}
}
if ($i == 0)
{
echo 'All good!';
}
?>
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.