Views base64 encoded blob in HTML with PHP
13,372
Try this:
echo '<img src="data:image/png;base64,'.base64_encode($blob_data).'">';
Author by
Christopher
Updated on June 04, 2022Comments
-
Christopher almost 2 years
having a bit of trouble Im trying to view a base64 encoded image which is held on my server as a blob. I want to view this inside either with an image tag or echo it as an html file which I can reference to with an image tag.
The problem is the blob data returns wrong from my server.
<?php $select = "SELECT `data` FROM `sandbox`.`photos` WHERE `id` = 4 LIMIT 0 , 1"; $result = mysql_query($select, $connection); while($row = mysql_fetch_array( $result )){ $blob_data = $row[0]; echo "$blob_data"; } ?>
The problem is that this retuns 5.533782782 * E.
How do I view this as an image? Do I need to deencode it?
-
Christopher over 12 yearsthanks however I want to dynamically reference the images so to the database they go.
-
twsaef over 12 yearsWhat aspect of a 'dynamically referenced' image precludes storing it in the filesystem?
-
HorusKol over 12 yearsOr you could do that - but I don't think that is 100% cross-browser