File: /var/www/content-sp/work-sp/find_missing_image_master.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
include_once('config.php');
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$root_link = $protocol . $_SERVER['HTTP_HOST'] . '/';
$masterId = $_REQUEST['master_id'];
$colm = $_REQUEST['colm'];
if ($masterId != '' && $colm != '') {
$master = $conn->query("select source from `csp_sp_master_category` where master_id='$masterId'");
$rowM = $master->fetch_assoc();
$mtype = $rowM['source'];
if ($mtype == 'OLY') {
$image_folder = "/var/www/content-sp/uploads/tet_admin_photos_oly/";
} else if ($mtype == 'SP') {
$image_folder = "/var/www/content-sp/uploads/tet_admin_photos_sp/";
} else {
$image_folder = "/var/www/content-sp/uploads/tet_admin_photos/";
}
$getQuesQuery = "select question_id, $colm from `csp_sp_question` where master_id='$masterId' AND $colm like '%img%' order by question_id";
$queryCon = $conn->query($getQuesQuery);
$missing_images = [];
if ($queryCon->num_rows > 0) {
while ($row = $queryCon->fetch_assoc()) {
$html = $row[$colm];
$question_id = $row['question_id'];
// Extract image paths from HTML content using regex
preg_match_all('/<img[^>]+src=["\']([^"\']+)["\']/', $html, $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $image_path) {
// Get the image filename
$image_file = basename($image_path);
$full_path = $image_folder . $image_file;
// Check if the file exists in the folder
if (!file_exists($full_path)) {
$missing_images[] = $question_id . ": " . $colm . "====" . $image_path;
}
}
}
}
}
} else {
echo "select master and column name";
}
$conn->close();
// Display missing images
if (!empty($missing_images)) {
echo "<h3>Missing Images:</h3><table>";
$i = 1;
foreach ($missing_images as $img) {
echo "<tr>";
echo "<td>$i</td>";
echo "<td>$img</td>";
echo "</tr>";
$i++;
}
echo "</table>";
} else {
echo "<p>All images are present.</p>";
}
?>
<style>
table,
th,
td {
border: 1px solid #ccc;
border-collapse: collapse;
}
</style>