How can PHP be used to store image IDs in a MySQL database without storing the actual image files?

When storing image IDs in a MySQL database without storing the actual image files, you can upload the images to a server and store their file paths in the database. This way, you can retrieve and display the images by using the file paths stored in the database.

// Upload image to server
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
move_uploaded_file($_FILES["image"]["tmp_name"], $target_file);

// Store image ID and file path in MySQL database
$image_id = 1; // Example image ID
$image_path = $target_file;
$sql = "INSERT INTO images (id, path) VALUES ('$image_id', '$image_path')";
$result = mysqli_query($conn, $sql);

// Retrieve image path from database
$sql = "SELECT path FROM images WHERE id = '$image_id'";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$image_path = $row['path'];

// Display image
echo '<img src="' . $image_path . '" alt="Image">';