Page 1 of 1

Database image storage versus disk based storage

Posted: Wed Jul 27, 2005 3:47 pm
by denz
Hi All,

I'm currently designing a website which I expect to grow quite large. This website will contain a lot of news stories which will contain many images, plus image galleries. I thought that storing all of the images in a MySQL database would be an efficient way to manage the images. Then I considered that perhaps storing in a datbase could not be the most efficient method of storage in terms of speed.

So, my question is this - What is the *prefered* method of image storage for you guys, can you point me in the right direction on this topic. Prehaps on this forum (I've tried searching but there are too many results! :oops: ), or elsewhere on the 'net?

I'm sure there are, and have been, many discussions about this and I would be very interested in finding others views on this subject.

Thanks

Posted: Wed Jul 27, 2005 4:04 pm
by timvw
Imho there is only one specialized system for file storage: the filesystem.

Usually, you choose for an in-between. Store the files in the filesystem and then store the path somewhere in your dbms...

Posted: Wed Jul 27, 2005 4:19 pm
by nielsene
timvw's post++

There are only two reasons I can think of for putting the image binary/blob into the database and they are both very rare.
1) You can lock down access to the database better then the filesystem in some shared hosting environments and/or you have a bigger quota in the DB than on the machine.

2) You have some amazingly stored procedures/custom datatypes in the DB that let you know interesting image-based matching, etc

Posted: Wed Jul 27, 2005 6:07 pm
by Ambush Commander
Note that if you have your MySQL databases on their own servers, and they actually have to talk to your HTTP servers on another machine, transferring all that information's gonna take up a lot of bandwidth on whatever connection you've got the two hooked up by.

Re: Database image storage versus disk based storage

Posted: Wed Jul 27, 2005 8:51 pm
by stukov
denz wrote:What is the *prefered* method of image storage for you guys, can you point me in the right direction on this topic. Prehaps on this forum (I've tried searching but there are too many results! :oops: ), or elsewhere on the 'net?
I saw many people doing:
Small size images -> database
Others -> filesystem

But, as timvw said, storing only the path to the file in the database would be an efficient way - well, this is what I do and it works pretty good.

Posted: Thu Jul 28, 2005 2:50 am
by denz
great! thanks for your help guys

Re: Database image storage versus disk based storage

Posted: Sun Aug 14, 2005 3:10 pm
by npeelman
denz wrote:Hi All,

I'm currently designing a website which I expect to grow quite large. This website will contain a lot of news stories which will contain many images, plus image galleries. I thought that storing all of the images in a MySQL database would be an efficient way to manage the images. Then I considered that perhaps storing in a datbase could not be the most efficient method of storage in terms of speed.

So, my question is this - What is the *prefered* method of image storage for you guys, can you point me in the right direction on this topic. Prehaps on this forum (I've tried searching but there are too many results! :oops: ), or elsewhere on the 'net?

I'm sure there are, and have been, many discussions about this and I would be very interested in finding others views on this subject.

Thanks
Define 'Quite large'? Yes, as the others have posted you can store the path to the images in th DB and call by the URL but, if you are going to be storing thousands upon thousands of images then you may run into some filesystem restraints. You can lose time (efficiency) by having too many files in one directory. You would have to split (catagorize) them somehow.
If you store the images in the database then you need a simple script to output them - no big deal. And one big advantage to keeping them in the DB is backups... you don't have to worry about your news articles and images being out of sync. When you backup the DB, everything is backed-up, text, images, everything.

Norm

Posted: Sun Aug 14, 2005 3:33 pm
by McGruff
Storing images in a db would feel like keeping my shoes in the fridge.

Posted: Tue Aug 16, 2005 5:15 am
by Bitmaster
...Storing images in a db would feel like keeping my shoes in the fridge...

Well here's an idea: some web hosting companies don't allow the user apache is running as (usually "nobody" or "apache") to have write access to the filesystem, so you use a database or you don't write anything to the disk...

I know this because I ran into the same problem with a customer recently :)

Posted: Tue Aug 16, 2005 5:18 am
by timvw
In that case i would suggest you to buy a shoebox instead of a refrigerator for storing shoes (Read: there are more than enough webhosters out there, get one who knows what he's doing :p)

Posted: Tue Aug 16, 2005 11:41 am
by McGruff
If you're having trouble writing files with php chmod the parent folder 0777 *temporarily*. Now you can make a dir with php so when you chmod the parent folder back to something safer - like 0755 - the dir you made can be written to by php scripts.

Same thing with files. Once you have created a file with php, you can continue to write to it after the non-php-owned parent dir has been chmod'd back to 0755.

Posted: Tue Aug 16, 2005 11:45 am
by Ambush Commander
Interestingly, once I CHMODded something to 0777, and it didn't work, and when I CHMODded it to 0755, it did work... so 777 is the solution to everything, but it's worth a try.

Posted: Tue Aug 30, 2005 5:06 am
by vd
storing your images in the database will cause problems uploading a dump e.g with phpMyAdmin, when "upload_max_filesize" and "post_max_size" were set to a lower value than the total filesize.