Jump to content

Archived

This topic is now archived and is closed to further replies.

ThE_eNd

pictures, in or out of the database

Recommended Posts

Hi.

 

I'm creating a database that will contain quite a few pictures (700MB - 1GB) and i was wondering how would you recommend handeling them? Should i put them in the database itself or should i use links to them.

 

I think using links might be a lot easier than putting the pictures in the database but then i'm worried about protecting the pictures.

 

Any ideas?

Share this post


Link to post
Share on other sites

using database to store images would also slow down the backup process. if you worry about protecting the images, you can store them in a directory that is password protected with .htaccess, or in a directory above the web root (above httpdocs, or www, or public_html, etc), then use php file functions and headers to retreive the images.

Share this post


Link to post
Share on other sites

[!--quoteo(post=321482:date=Nov 23 2005, 10:18 AM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Nov 23 2005, 10:18 AM) 321482[/snapback][/div][div class=\'quotemain\'][!--quotec--]

... or in a directory above the web root (above httpdocs, or www, or public_html, etc), then use php file functions and headers to retreive the images.

 

 

that sounds interesting, how can i do that?

where do i look for info on how to do that?

 

if the folders a protected with .htaccess are the pix safe from web spiders and software that downloads entire sites?

Share this post


Link to post
Share on other sites

[!--quoteo(post=321501:date=Nov 23 2005, 11:05 AM:name=ThE_eNd)--][div class=\'quotetop\']QUOTE(ThE_eNd @ Nov 23 2005, 11:05 AM) 321501[/snapback][/div][div class=\'quotemain\'][!--quotec--]

that sounds interesting, how can i do that?

where do i look for info on how to do that?

 

if the folders a protected with .htaccess are the pix safe from web spiders and software that downloads entire sites?

 

let's say you have these folders under your username:

/username/images

/username/public_html

 

images would not be accessible directly from the domain. so you'd need a script to be the "middleman".

 

getImg.php

<?
$path = '/username/images/';
$file = $_GET['file'];
$fileType = 'image/jpeg';

// set the correct header and output the file. make sure no html and echoes are used before this line
header('Content-type: '.$fileType);
echo file_get_contents($path.$file);
?>

as simple as that. now, in your webpages:

<img src='http://www.yourhost.com/getImg.php?file=pic1.jpg'>

that's basically it!

your images are protected from downloading because they have the extention .php. Now you can incorporate the database records into this script to further secure your images. instead of file=pic1.jpg, you could use fileID=10 and fetch the file name and extension from the database.

 

onto the .htaccess part. web spiders are not able to access the folder. i don't know about site downloading software, but i think they cannot access the folder.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.