With the following script you can detect missing or not readable image files, based on your product collection. Good before project launch or after product imports.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<?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!'; } ?> |
Find the Gist here.