0

So I've got some images stored in a MySQL database as BLOB's (I know it's better to just store the directory and do it that way, but this is what I need to do for now) and I need to display them on a webpage. Now, I know how to make a script and give it an image header and pull the img src from there, but I have a lot of images from different places for different uses, so I'd have to make a ton of these scripts and I'd rather not clutter up my files like that. Anyway, does anyone know of a function or something I can use to display the image that will run on the same page?

2 Answers 2

2

This is what I've done in php to call an image stored a blob in mysql

img width=120 height=120 src="data:image/png;base64,'.base64_encode($row['Image']).'
Sign up to request clarification or add additional context in comments.

Comments

0

Use a data: URI to hold the image.

3 Comments

Pardon my noobishness, but I've never heard of this technique. I'm reading up on it now, but could someone explain how I would go about using it? Thanks
Wherever you would have http://... in a img src, you instead put data: followed by the mimetype, the encoding, and the encoded image data.
Ah, very interesting. Thanks, I'm gonna try this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.