Page 1 of 2

Better to have database point to image than store?

Posted: Wed Jun 30, 2004 10:40 pm
by bradles
I am reasonably new to PHP/MySQL but have managed to set up apache, mysql and php on my system to do testing.

As a photographer I wish to store my client's images online so they can login to my site and see their own page with all their images. Is it better to have their images stored on the site in a folder and have the database point to that folder rather than trying to store them in the database? Sorry if the question seems a little ambiguous.

Posted: Wed Jun 30, 2004 10:47 pm
by m3mn0n
I'd recommend inside the db.

Posted: Wed Jun 30, 2004 11:26 pm
by ol4pr0
Howcome that sami, i am currently working with fotos aswell, asin pasfotos from Curriculums however i have stored the file path instead of the fotos. So kinda wondering if and why i should change that !

Posted: Thu Jul 01, 2004 12:19 am
by phice
I guess Sami likes to make the server work harder than it should. ;)

Posted: Thu Jul 01, 2004 3:10 am
by JayBird
I would say by the the better option is to keep the images in a folder within the site, and store the path to the image in the DB.

Also, if DB goes down, you don't lose your images!

Mark

Posted: Thu Jul 01, 2004 3:54 pm
by EricS
I'm finishing up a shopping cart specifically designed for photographers. I've tried both ways in the process and settled on storing the photos as files. Mostly because I didn't want to bloat the database and I had much faster page processing times and a lot let calls to the database doing it this way. Basically my decision was strictly speed based.

I do not store the path to the images in the database either. Just an identifier. The path to the file is actually built dynamically at a later date. This allows the entire system to be completely portable at a later date.

Posted: Thu Jul 01, 2004 4:43 pm
by tim
i would store the path simply for the fact if the db poops on you you dont lose images. i'm on dial-up, to upload big image files would take me forever.

(Yes I know its has been stated, just agreeing)

:wink:

Posted: Thu Jul 01, 2004 7:30 pm
by m3mn0n
Well, I was thinking about the security perks of having them in a db, since this is not just normal images, these are a photographers pictures we're talking about. ;)

But both methods are suitable and if you use .htaccess files, security won't be a problem with storing them in folders either.

Posted: Thu Jul 01, 2004 8:26 pm
by EricS
I have security built into my shopping cart. Photographers are allowed to pick and choose what photos each customer is allowed to see, its all a part of the overall security of the shopping cart and I'm not using .htaccess to implement it. So you don't have to store the photos in the db to get security for the photos. There are many other ways.

Posted: Thu Jul 01, 2004 11:30 pm
by ol4pr0
Well i am i guess of all these explotions about whether to store it in db or just have them in some folder. The only thing that might make a differance is whether you want security and what kind of security.
EricS wrote: I had much faster page processing
I had the same feeling when i tried that.
Didnt record it tho so just the feeling.

Posted: Fri Jul 02, 2004 3:00 am
by JayBird
EricS wrote:I have security built into my shopping cart. Photographers are allowed to pick and choose what photos each customer is allowed to see, its all a part of the overall security of the shopping cart and I'm not using .htaccess to implement it. So you don't have to store the photos in the db to get security for the photos. There are many other ways.
if not using .htaccess, how to you stop people directly access the images?

Mark

Posted: Fri Jul 02, 2004 4:39 am
by WaldoMonster
My experience is that if you have many small images (50x50 pixel) on one page it is faster to store them in the database. Maybe it has something to do with the hd seek time.

Posted: Fri Jul 02, 2004 11:45 pm
by m3mn0n
Bech100 wrote:
EricS wrote:I have security built into my shopping cart. Photographers are allowed to pick and choose what photos each customer is allowed to see, its all a part of the overall security of the shopping cart and I'm not using .htaccess to implement it. So you don't have to store the photos in the db to get security for the photos. There are many other ways.
if not using .htaccess, how to you stop people directly access the images?

Mark
My question exactaly.

What's to stop someone from going http://yorusite.com/cart/images/supercoolimage.jpg and stealing it?

If they can see one image, then there is a good chance they can right click on it, and see it's folder location, and then simply guess names (especially bad if they are simple like image001.png).

Posted: Tue Jul 06, 2004 6:41 am
by EricS
The files are not stored in a web accessible directory. All images are retrieved by PHP, not from Apache directly. Therefore I can use user & group security on the retrieval of images.

Have you figured it out now? I'm trying to give you hints about how to do it with out coming right out and telling you. I think you will learn more if I guide toward the answer rather than just giving it to you.

Posted: Thu Jul 08, 2004 12:48 pm
by nutstretch
i just store the name of the image in the field and then if for some reason your path changes you only have to change the path in the code not on every record.