Home > Backend Development > PHP Tutorial > How to Display Images Stored as BLOBs in MySQL within HTML?

How to Display Images Stored as BLOBs in MySQL within HTML?

Linda Hamilton
Release: 2024-12-15 13:45:12
Original
591 people have browsed it

How to Display Images Stored as BLOBs in MySQL within HTML?

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>
Copy after login

Image Retrieval Script (getImage.php):

$link = mysqli_connect("localhost", "root", "", "dvddb");
$sql = "SELECT dvdimage FROM dvd WHERE>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template