<?php
include "../database/database.php";
include "../database/data.php";

// Fetch image data from database
$sql = "SELECT image FROM imv_product WHERE id = '17'";
//$sql = "SELECT image FROM images WHERE id = '3'";
$result = $connection->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    header("Content-type: image/png");
    $imageData = $row['image'];
    echo $imageData;

    // Display the image directly in HTML using base64 encoding
   // echo '<img src="data:image/jpeg;base64,' . base64_encode($imageData) . '" class="img-fluid mb-3" alt="Sample Image">';
} else {
    echo "Image not found.";
}





// $sql = "SELECT image FROM imv_product WHERE id = '1'";
// $result = $connection->query($sql);

// // Check if the query was successful
// if ($result === false) {
//     die("Error executing query: " . $connection->error);
// }

// if ($result->num_rows > 0) {
//     $row = $result->fetch_assoc();
//     $image_data = $row['image'];
    
//     // Debug: Check the size of the image data
//     error_log("Image data size: " . strlen($image_data));

//     // Clear the output buffer to avoid any extra whitespace
//     ob_clean();

//     // Assuming the image type is JPEG
//     header("Content-type: image/jpeg");
//     echo $image_data;
// } else {
//     echo "Image not found.";
// }

?>
<!-- UPDATE `imv_product` SET `image`='' -->