pls help me to do this.
i m saving my image in php mysql and retriving with js - base64

i cant get code exactly.

i m retriving. like this code

<img src="LzlqLzRBQVFTa1pKUmdBQkFRQUFBUUFCQUFELzJ3.....<continue code>" />

I want src like below:

<img src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAA />

Edited by pritaeas: Not a code snippet.

4 Years
Discussion Span
Last Post by gon1387

if you're retrieving it with JS, why not retrieve the path of the image instead? Are you storing the images in DB? Or do you have the images path, located outside your document root?

Going back, was the data uri, sent through AJAX?
for data URI you have to preappend this to the Base64 encoded blob:

data:[MIME TYPE];base64,

Can you show us how you process and retrieve your image?
ussually it's done like this:

//You retrieve the imageblob eithre from a file or a stored blob in the DB
$encodedBlob    = base64_encode($imageBlob);

//Make sure you know the MimeType of the image
//You can use Exif, GD, or whatever you have in your sleeves
$imageDataURI   = "data:" . $imageMimeType . ";base64," . $encodedBlob;

Edited by gon1387


Anyhow, just an additional thought, retrieving images in this fashion, would most likely burden your server or gives a tremendous amount of time to load the page / just the image, as conversion of blob to Base64 expands the data.

Edited by gon1387

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.