Closed Nicero closed 7 years ago
You can encode and decode the BLOB image content yourself for saving and fetching data for database.
BTW, I think it is not a good idea to save image content into database. Using file system or third-party image storage provider is better.
Thank for the fast answer. Encoding the image before adding it to a BLOB worked fine:
$blob = file_get_contents("Image00001.jpg");
$last_user_id = $database->insert("images", [
"image" => base64_encode($blob_01)
]);
Read the image from dB:
$datas = $database->select("images", [
"image"
], [
"id[>=]" => 1
]);
$a = $_GET['jsoncallback'] . '(' . json_encode($datas) . ');';
echo to Ajax:
echo $a;
I have some images saved into BLOB. I can retrieve the images like this:
and display them with PHP like this:
echo '<img src="data:image/jpeg;base64,'.base64_encode($data['image']).'"/>';
Now I would like to send the result query via Ajax in JSON format and then display the image using Javascript. The following code works fine for text fields but not for images saved into BLOB:
because at the images is not applied
base64_encode
first .How do I add
base64_encode
toimage
before sending it tojson_encode
using Medoo?