Images in database or file, which is best?

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Just getting my dating site up and running again and the new script allows you to choose how members' photos are stored. I there any difference between db storage and file storage? I'm thinking that storing all images in a folder is better just so I have a more concrete copy of them than a few numbers in a db, but am I just being silly?
 

Shovel

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,350
It doesn't make much difference.

In the DB, it's perhaps easier for you since you don't need to set up any filesystem permissions for the file creations.

However, I don't know how well some of these dynamic image serving scripts work with caching. I'd be wary that some caching mechanisms won't like them and as such, you might find bandwidth usage is higher.

You could get around that caching thing with some good URL rewriting though, to make the images referenced as if they were physical files.

Finally, it costs you more in processing time and memory usage to pull images out of the database than just serving up a file. Given that shared-hosting web hosts care about things like that, there's merit in minimising such things.
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Thanks, I think I'll keep them in a folder.
 

Chilly

Balls of steel
Joined
Dec 22, 2003
Messages
9,047
I would have thought the db would just contain references to the pictures, not the binaries themselves?
 

Panda On Smack

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,030
I guess you could just store the filename but you might as well store the binary data in there as well if you do that.
 

Shovel

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,350
Chilly said:
I would have thought the db would just contain references to the pictures, not the binaries themselves?

It could, but I took it to mean that the image data itself was being stored in a blob, rather than on the filesystem.

If it's just storing pointers to physical images, I don't see there's much real difference between the two options.
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
You're right, the images are either in a folder or stored in the database as data with no images in a folder anywhere.

I think I prefer to have them in a folder so the db doesn't get too large and slow down.
 

wyrd_fish

Fledgling Freddie
Joined
Dec 27, 2003
Messages
537
how do you go about storeing images in a DB?

i usually just store the filename, and link to it in a dynamic stylee
 

JingleBells

FH is my second home
Joined
Mar 25, 2004
Messages
2,224
They can be stored as a BLOB (Binary Large OBject) type, no idea as to how you go about adding/retreiving them from PHP though, would be easiest just to store filename in the DB and the file somewhere in the filesystem.
 

Panda On Smack

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,030
I do it all the time with ASP/SQL

Im sure its similar in PHP, you just read the binary data and then BinaryWrite it telling the browser the ContentType

Its pretty simple.
 

Padwah

Fledgling Freddie
Joined
Dec 25, 2003
Messages
127
It depends on how busy the site is and how many other data calls are being made. Storing image data in a database is convenient but if your site is getting hit a lot then the data access will slow things down quite a lot. Much better to either store a reference to the image location or the folder where the image is stored than actuall store the image in the database.
 

Users who are viewing this thread

Top Bottom