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

kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

Yep put the images in a folder above the web root. Then use some trickery with PHP to get the image from that non web accessible folder and display the image. You can even use some simple checks to try and stop people from leaching images from your site. Also, another good reason for storing a link to the image location and not the image itself is if you have a seperate web server just for images. This is normally only done on high volume sites but it makes it easier to implement if the images aren't in a db.
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

Post by EricS »

Here's a quick tip I've use when storing images in folder's but storing the image info in a database.

Normally all my images are just numbers.ext EG 1.gif or 2.jpg.

I then have a table in my database which stores the id #, the type (.gif/.jpg/.png/.tiff), and I have a height and width field.

I then simply construct an image field from the database

Code: Select all

$image = '<img src="'.$directory;
$image .= $idNumber.$type.'" height="'.$height.'" width="'.$width.'">';
Bare in mind I that if you store your images outside the web root, you will need to replace the data inside the src="" field with the url to the script that will extract and display the image.

You would then have security measure built into the image display script that authorizes or disapproves the display of the image.
Photographer
Forum Newbie
Posts: 4
Joined: Mon Nov 07, 2005 8:57 pm
Location: Canada

Post by Photographer »

Did anyone ever finish their online gallery/shopping cart for photographers?
I am looking to perchase the software & host the galleries on my website.

Please email me with a demo & price
angela@silk.net

Thank you
-angela
EricS
Forum Contributor
Posts: 183
Joined: Thu Jul 11, 2002 12:02 am
Location: Atlanta, Ga

No yet complete.

Post by EricS »

The project I was working on was stopped short because of budgetary reason on the client's side. So as of right now, the photo proofing and shopping application is uncomplete.

Eric Stewart
BZorch
Forum Commoner
Posts: 45
Joined: Mon May 02, 2005 10:42 pm

Post by BZorch »

I am doing something similar. I store the path name in the DB and store the folders outside of the www folder.By storing the path name in the DB, I can alter the path depending on if you are requesting thumbnails, med. res, or the high-res images.

So far, I do not regret this route. It seems it would be more difficult to do in a DB and require more hardware overhead. I considered using imagemagick to do the thumbnails and medium res on the fly, but decided it would be too slow as compared to files that are already made.

Unfortunately, to create the three copies of every file is a pain and tough to keep straight.
Post Reply