Home  >  Article  >  Backend Development  >  How to Display an Image Stored as a BLOB in MySQL Without Interfering Content?

How to Display an Image Stored as a BLOB in MySQL Without Interfering Content?

Barbara Streisand
Barbara StreisandOriginal
2024-10-21 06:19:30846browse

How to Display an Image Stored as a BLOB in MySQL Without Interfering Content?

Displaying an Image Stored in a MySQL BLOB

When presenting an image stored as a BLOB in a MySQL database, it's crucial to avoid echoing any other content before or after the image data. This can interfere with the browser's ability to display the image.

To resolve this issue and enable the display of both an image and other content, consider using the following technique:

Convert the image data into Base64 format and embed it within an tag:

<code class="php">echo '<img src="data:image/jpeg;base64,' . base64_encode($row['imageContent']) . '" />';</code>

This approach allows for the display of additional content, such as text, after the image. However, it's important to note that this method is not optimal for performance or caching, particularly on mobile devices. For better performance, consider alternative methods such as storing the image separately from the database.

The above is the detailed content of How to Display an Image Stored as a BLOB in MySQL Without Interfering Content?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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