displaying an image stored in a mysql blob

You can convert the image data into base64 and stick it in an <img> tag. Currently, you are trying to write text outside of the image data, and the internet browser thinks your text is part of the image and thus throws an error.

Try something like this:

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

Note, this isn’t the best solution because it cannot be cached and is fairly slow, especially on mobile phones. Check out the caniuse for data URIs.

Leave a Comment