I have this database that contains images as strings. Those strings look something like this:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD...
I need to create a link that will display this image. Like something.com/?id=27
is an image. All the images are in jpeg format. Here's what I've tried but didn't work:
<?php
$host = "smth";
$user = "smth";
$pass = "smth";
$db_name = "smth";
$dbh = new PDO("mysql:host=$host;dbname=$db_name", $user, $pass);
$dbh->exec("SET NAMES utf8");
$q = $dbh->prepare("select content from img where id = :id");
$q->execute(array(':id'=>$_GET['id']));
$row = $q->fetch(PDO::FETCH_BOTH);
header("Content-type: image/jpeg");
echo $row['content'];
?>
The data is being fetched correctly but the image is not displayed.
I need to be able to use this link like this <img src="mysite.com?id=21" />
and I do NOT want this solution: <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABA..." />
Thanks!