Better to have database point to image than store?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Better to have database point to image than store?

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I'd recommend inside the db.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 !
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I guess Sami likes to make the server work harder than it should. ;)
Image Image
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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:
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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).
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post 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.
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post 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.
Post Reply