Displaying Images from MySQL Database in HTML
Problem Statement:
Users seeking guidance on retrieving and displaying images stored in a MySQL database as BLOB columns within HTML elements face challenges involving the $result variable in PHP.
Solution:
Directly accessing $result in HTML is not feasible. Instead, an additional PHP script is required to extract the image data and present it.
Modified PHP Script (catalog.php):
<body> <img src="getImage.php?id=1" width="175" height="200" /> </body>
Image Retrieval Script (getImage.php):
$link = mysqli_connect("localhost", "root", "", "dvddb"); $sql = "SELECT dvdimage FROM dvd WHERE>
How It Works:
The modified catalog.php creates an image tag with a source pointing to getImage.php and specifies the desired dimensions.
getImage.php establishes a MySQL connection, executes the query to retrieve the image data, and extracts the image column into $image.
Subsequently, it sets the header content type to "image/jpeg" and outputs the image data, allowing it to be displayed in the HTML image tag.
The above is the detailed content of How to Display Images Stored as BLOBs in MySQL within HTML?. For more information, please follow other related articles on the PHP Chinese website!