<?
php
// Database connection details
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the image ID from the URL (e.g., image.php?id=1)
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Prepare and execute the SQL query
$stmt = $conn->prepare("SELECT image_type, image_data FROM images WHERE id
= ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($image_type, $image_data);
if ($stmt->fetch()) {
// Set the Content-Type header
header("Content-Type: " . $image_type);
// Output the image data
echo $image_data;
} else {
echo "Image not found.";
}
$stmt->close();
} else {
echo "Image ID not provided.";
}
$conn->close();
?>