Edited and started over to better describe my issue.
I have this code that displays an image from a database using blob data.
function getContent($db) {
$query = "SELECT name, animalid, image, thumb FROM images ";
$sql = $db->prepare($query);
$sql->execute();
return $sql->fetchAll();
}
$data = getContent($db);
foreach($data as $row) {
$id = $row['id'];
$image = $row['image'];
$thumb = $row['thumb'];
echo '<img src="data:thumb/jpg;charset=utf8;base64,'.$image.'">';
}
This code displays a image on the page, when viewing the source code i see the blob data that the image is made from, what i need is to actually make an image that i can name properly.
How do i make a ******.jpg from the blob data?
Use base64_encode
. You should use image/jpeg
MIME type without charset
.
function getContent($db) {
$query = "SELECT name, animalid, image, thumb FROM images ";
$sql = $db->prepare($query);
$sql->execute();
return $sql->fetchAll();
}
$data = getContent($db);
foreach($data as $row) {
$id = $row['id'];
$image = $row['image'];
$thumb = $row['thumb'];
// $image is the BLOB
echo '<img src="data:image/jpeg;base64,'.base64_encode($image).'">';
}