Checking for missing images script
Posted: Tue Nov 29, 2022 4:29 pm
Hi Guys,
Please can some one have a look at the code below and hazard a guess as to why it 1. It does not work and 2. It returns no errors
The code is supposed to check the product image name in the and then check the /images folder for a corresponding image and report back if the image is missing in the folder.
I have either totally mucked it up or I am missing something simple
Please can some one have a look at the code below and hazard a guess as to why it 1. It does not work and 2. It returns no errors
The code is supposed to check the product image name in the and then check the /images folder for a corresponding image and report back if the image is missing in the folder.
I have either totally mucked it up or I am missing something simple
Code: Select all
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set("display_errors", 1);
require 'includes/application_top.php';
require 'includes/template_top.php';
//Change this line if you keep your images stored in a strange directory.
//Don't touch it unless you're having problems.
$image_directory = DIR_FS_CATALOG . 'images/';
$column_query_string = '';
$image_count = 0;
$image_columns = '';
if (is_iterable($image_columns)) {
foreach ($image_columns as $column) {
if ($column_query_string != '') $column_query_string .= ', ';
$column_query_string .= $column;
}
}
$image_array = array();
$images_query = $db->query("SELECT products_id, ' . $column_query_string . ' from products");
while ($row = $images_query->fetch_assoc()) {
$image_array[$row['products_id']] = array();
if (is_iterable($image_columns)) {
foreach ($image_columns as $column) {
if ($row[$column] != '') {
$image_array[$row['products_id']][] = array('products_image' => $row[$column], 'column' => $column);
$image_count++;
}
}
}
}
/* Our image array is now built, start checking files. */
$missing_images = array();
foreach ($image_array as $id => $product) {
foreach ($product as $image) {
if (!is_file($image_directory . $image['products_image'])) {
if (!is_array($missing_images[$id])) $missing_images[$id] = array();
$missing_images[$id][] = $image['products_image'];
}
}
}
?>
<table class="table w-75 mt-4 mx-auto">
<thead class="thead-light">
<tr>
<th><?php echo 'Product id'; ?></td>
<th><?php echo 'Product name'; ?></td>
<th><?php echo 'Product image'; ?></td>
</tr>
</thead>
<?php
foreach ($missing_images as $id => $files) {
$product_query = $db->query("SELECT products_id, products_name, products_image FROM products_description pd INNER JOIN products p ON p.products_id = pd.products_id ORDER BY p.products_id");
$product = $product_query->fetch_assoc();
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $product['products_name']; ?></a></td>
<td>
<?php
if (count($missing_images) > 0) {
if (is_array($files) || is_object($files))
{
foreach ($files as $f) {
echo $f . '<br />';
}
}
?>
</td>
</tr>
<?php } } ?>
</tr>
</table>
<?php
require 'includes/template_bottom.php';
require 'includes/application_bottom.php';
?>