Reputation:
i have a small problem with my code. I'm trying to show an image out of my database on my homepage using php (pdo). Problem is: I don't really know how to let insert the variable of the image in the HTML img tag. Where is my mistake / How can I fix it?
I am saving the images in my mysql database as a blob (largeblob) and all images are .jpg and / or .png
<?php
$db = new Dbh;
$pdo = $db->connect();
$counter = 0;
$content = "";
$statement = $pdo->prepare('SELECT * FROM images');
$statement->execute();
while ($row = $statement->fetch()) { ?>
<img src = "<?php echo $row['image']; ?>">
<?php }
?>
The thing happening right now is, is that html just shows some kind of bit code full of strange symbols
Thanks for your help in advance!
Upvotes: 2
Views: 2665
Reputation: 141
This should work
echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['image'] ).'"/>';
Upvotes: 1