I have developed a script here for you to find and fix all products with broken images in your Prestashop store:
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 |
<?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>"; } } } |
Partner With Us
Looking for a partner to grow your business? We are the right company to bring your webstore to success.
Talk to Igor
Thanks for the script, it saves very much time
I want to show images with respect to color in categories page
for example i added a product in Men categorie with different two color i want to display one one picture from each color category page….
Murtaza, if your file is in the main directory then don’t change the path. Other way begin the path from the root directory.
Hi,
I am not understanding how to add code what is file name or how to include_once.Please guide me.
thanks
I am experiencing broken image in my prestashop shop. kindly assist me. Thanks
Thank you, saved me some time!
Syed,
Yes, you are absolutely right
better to replace with
Just tried this script and it finds products with image entries in database for images which do not exist in the filesystem.
The only catch is that it needs to use the prestashop variable for shop prefix or people should replace the “ps_” to shop specific prefix.
Jonathan,
The eight line is our code is
and here there is no “foreach”.
Thanks for the code. I got this error when I ran it:
Warning: Invalid argument supplied for foreach() in on line 8
Tran,
I will post a tips on that topic soon.
Hi Alex,
Very nice scripts, I think you you have a solution how to massive delete products from id for example 1000-3000 and their images from /img
Best regards
Tran
Hi Sebastian! You need to delete data about such images from the database.
script works great! so how do you fix broken images?
The code should be located in the Prestashop root directory or elsewhere. In the latter case, however, there are other paths for include_once.
Hello, where do you put the code