A Question Regarding CHMOD Permissions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eyal
Forum Newbie
Posts: 19
Joined: Mon Jun 19, 2006 11:03 am

A Question Regarding CHMOD Permissions

Post by eyal »

I've got a folder called "private_photos".
I don't want to allow users to view the content of that folder (By Simply Typing: "www.domain.com/private_photos/"), But Sometimes I want to show a photo from that folder in my webpage.

How can I set the CHMOD in a way that No one can just view the content of the folder, but still show a specific photo from that folder on my site?

Of course the names of the photos are encrypted so no one can just guess the name of the photo.

Thanks once again!
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

use a "fetch" script that pulls the selected file from a protected directory either via .htaccess or storing it outside of the document root...

Instead of accessing the file normally, like:

Code: Select all

<img src="protected/myimage.gif" />
you would go with something like:

Code: Select all

<img src="fetch.php?path=protected/myimage.gif" />
Cheers :)

Edit: I should note that you would need to perform a aothorization check on the file being fetched...otherwise it's no more secure.
eyal
Forum Newbie
Posts: 19
Joined: Mon Jun 19, 2006 11:03 am

Post by eyal »

Should I write any code inside the fetch.php file?
eyal
Forum Newbie
Posts: 19
Joined: Mon Jun 19, 2006 11:03 am

Post by eyal »

Hockey wrote:use a "fetch" script that pulls the selected file from a protected directory either via .htaccess or storing it outside of the document root...

Instead of accessing the file normally, like:

Code: Select all

<img src="protected/myimage.gif" />
you would go with something like:

Code: Select all

<img src="fetch.php?path=protected/myimage.gif" />
Cheers :)

Edit: I should note that you would need to perform a aothorization check on the file being fetched...otherwise it's no more secure.
Would you mind to explain to me what code should I write in the fetch.php page?

Thank for your Help!

Eyal
Post Reply