tags:

views:

208

answers:

2

I'm implementing a website where images are stored in a database. These are two tutorials that I've come across with two different ways of storing and retrieving image data.

Which one would you recommend, and why?

http://www.developertutorials.com/tutorials/php/storing-images-database-050620/page1.html

http://www.onlamp.com/pub/a/onlamp/2002/05/09/webdb2.html?page=2

+2  A: 

2nd one. The first involved creating a base64 string, and then storing it in the DB. Essentially, this means that you will have **at least** two copies of the image in memory as it marshals that base64 string. The second stores it in the DB as a blob, avoiding the CPU time and memory resources allocated to the marshaling.

Wayne Hartman
A: 

This is just something to consider as I don't know really know the details, but I seem to remember there being some way to render images directly in websites without linking to external files. I also seem to remember this being base64. I may be way off, but if there was a way to store the images that would allow direct embedding, there may be some advantages to that.

Daniel Straight
You're probably thinking of data: URLs. data: URLs aren't supported in IE prior to version 8. Using data: URLs for images of any significant size is probably not a great idea, as base64 encoding increases the size by a third, and inlining images like that destroys the browser's abiity to cache them. Even if it weren't for all of that it'd still probably be better to store the images in binary form and base64 encode them when necessary rather than storing them in base64 unless you knew you'd *always* want them in base64, and it turned out that base64 encoding them on demand was too expensive.
Laurence Gonsalves