Reputation: 108
Good day
I'm trying to show an image using DATA URIs and encoding a string in base64 as shown below:
<img src="data:image/jpeg;base64,<?php base64_encode($FOTO) ?>" />
The image (JPG) is stored in the database in this way:
The problem is that using that DATA URI, it does not show the image on the screen. I don't know the error or if I have to do something different to be able to show that stored image.
Is there any other way to display these images stored in SQL Server?
Thank you very much for your time.
Upvotes: 1
Views: 7544
Reputation: 1929
The data in db is not base64, you need to convert this hexadecimal data to base64. Php, as I know doesn't have a direct function to do that but it can be achieved with pack()
. I leave it to you as homework to study this function.
Convert the data from db to base64 like:
$fFoto = base64_encode(pack('H*', $foto));
Then pass this $fFoto
to image src
like you are already doing.
<IMG src="data:image/jpeg; base64, <?php echo $fFoto; ?>" />
Upvotes: 1