Jump to content

How to find all products with broken images


Recommended Posts

Hi,

Tool for finding broken images:

<?php
include_once('config/config.inc.php');
include_once(_PS_ROOT_DIR_ . '/images.inc.php');

error_reporting(E_ALL);
ini_set('display_errors', 'on');

$sql = 'SELECT * FROM ps_product LIMIT 1000';
$products = Db::getInstance()->ExecuteS( $sql );
foreach($products as $product){
$productObj = new Product($product['id_product']);
$id_lang = Configuration::get('PS_LANG_DEFAULT');
$images = $productObj->getImages($id_lang);
$ps_legacy_images = Configuration::get('PS_LEGACY_IMAGES');
foreach($images as $image){
	// legacy mode or default image
	if ($ps_legacy_images) {
		$filename = _PS_PROD_IMG_DIR_ . $product['id_product'] . ($image['id_image'] ? '-' . $image['id_image'] : '') . '.jpg';
	} else {
		$imageIds = $productObj->id . "-" . $image['id_image'];
		$split_ids = explode('-', $imageIds);
		$id_image = (isset($split_ids[1]) ? $split_ids[1] : $split_ids[0]);
		$filename = _PS_PROD_IMG_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . '.jpg';
	}

	if(!(file_exists($filename))){
		 echo "File is not exist: " . $filename . ". ID product - " . $productObj->id . "<br>";
	}
}
}

 

Regards

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...
  • 1 year later...
×
×
  • Create New...