Home >Database >Mysql Tutorial >How Can I Display MySQL BLOB Images Alongside Other Content?
When working with MySQL BLOBs containing images, displaying the image while echoing other content can be problematic.
In the code snippet provided:
header("Content-type: image/jpeg"); echo $row['imageContent']; echo '--------'; // If echoed before the image, the image will not display
Outputting text before the image data will cause the image to not display. This is because browsers interpret the text as part of the image.
To display both text and the image, convert the image data into base64 and embed it in an tag:
echo '<img src="data:image/jpeg;base64,' . base64_encode($row['imageContent']) . '" />'; echo 'Hello world.';
Note that this method is not ideal for performance, as the image data is not cached and is slower to load on mobile devices. Consider using a more efficient solution if performance is critical.
The above is the detailed content of How Can I Display MySQL BLOB Images Alongside Other Content?. For more information, please follow other related articles on the PHP Chinese website!