PHP Display Image BLOB from MySQL
When attempting to display an image stored in a MySQL BLOB column, some users encounter issues where Chrome or IE display an image icon instead of the actual image. This can be due to the lack of proper encoding and the handling of the binary image data.
Solution
The correct way to display an image BLOB in PHP involves:
Preparing the Data:
Encoding the Binary Data:
Displaying the Image:
header("Content-Type: image/jpeg"); echo '<img src="data:image/jpeg;base64,' . base64_encode($image) . '" />';
Note: Ensure that the image data retrieved from the database is valid and that there are no trailing whitespace characters before or after the tags.
The above is the detailed content of How to Correctly Display Image BLOBs from MySQL in PHP?. For more information, please follow other related articles on the PHP Chinese website!