views:

52

answers:

4

I am using PHP/MySQL to handle the image uploading. I want all images that are uploaded to the logged in user's gallery to only be accessible by the logged in user. I do not want people to be able to guess the file name and directly link to it.

I am thinking that I can just store the images outside the webroot and access them through some PHP. However, if the user wants to later share the image with a friend via a link, how would I allow that?

Are there any other steps I need to take to make sure only the user can see their photos? I take user privacy very seriously and want to get this right.

Thanks for your help in advance!

A: 

You could use a profile(user)-based sharing system, where logged-in user A can indicate that logged-in user B is allowed to view image C, and can add/remove such permissions at will.

If linking viewing to a user account is not possible, you could have 'view passwords' on the images or on groups of images (such as a gallery); the URL to view the images would check if the user/owner is the one viewing and if not, it would demand the password.

Andrew Barber
+6  A: 

You are correct in your original assumption. Store your files outside of the public directory and use a PHP script to check authorization and display the image.

To get around the sharing problem you can give them an area where they can say "Share this photo" and it will display a URL like

http://www.yoursite.com/image/12390123?v=XA21IW

XA21IW would be some unique hash stored in a table and they can specify a lifetime or you can code one yourself. When the page loads and v is passed in you can lookup a table to determine if it is a valid hash for that image id.

You have some options here. Every time they click "Share this photo" you can:

  1. Destroy all old hashes
  2. Add on to the stack
  3. Allow them to configure an expiration etc...

Or simply allow images to be public/private.

methodin
+1 I was 2s away from posting something very similar.
ign
Thanks for the quick response. That is very similar to the approach I planned on taking. I basically wanted to make sure there wasn't a more secure way and that I wasn't forgetting anything. Thanks!
sherril8
A: 

I think there is no problem is storing the images outside the webroot and access them through some PHP. You can always access them with the php script, when ever user shares it.. even it is more secure to do so, beacuse you can always perform some security checks. before actually displaying the image.

Thanks.

Chetan sharma
A: 

You save image to your server, place image name, data what you need and some hash in you DB .... than you set path of image to php file called images.php where you receive this hash with GET and find image by hash from you DB and with header set to image/GIF example create image. Path to image will be images.php?hash=abcdefg.

Other thinks about user permission and so... I think there are some responds with this solutions... it is quiet easy...

jatt