Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I secure private photos that a user uploads on my site?

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!

like image 769
sherril8 Avatar asked Sep 28 '10 18:09

sherril8


People also ask

How can I share photos without losing quality online?

If you have a really large media file to send, we recommend using FileWhopper, an online file transfer service with no file size limits. With FileWhopper, you can send over files and folders of any size, even if it's a 10TB media pack. Your photos and videos will be delivered in original quality.


3 Answers

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.

like image 142
methodin Avatar answered Sep 27 '22 17:09

methodin


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.

like image 22
Andrew Barber Avatar answered Sep 27 '22 17:09

Andrew Barber


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.

like image 33
Chetan Sharma Avatar answered Sep 27 '22 18:09

Chetan Sharma