Hello,

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 />

Recommended Answers

All 2 Replies

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;

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.