Take a look at this, I think I have seen a video about it on laracast.
How to protect images and files
Hi folks, how can I protect images ( and other files as Videos, PDFs etc. ) for public viewing, and only show them to admins and the client it belongs to.
What I'm trying to build in Laravel, is a little file manager, where my clients could log in and see logos and other stuff, which belongs to them only. The problem, I have no clue where and how to start with it. So thanks for any help and advice on how to:
- protect files from public
- allow to view this files only to admins and belonging clients.
There are three approaches I can think of just now;
-
You intercept all image and video requests with Laravel, then using the router, serve up the content that the user was after, provided they are authorised. THIS WILL BE SLOW!
-
You rely on obscurity and put all that clients images, videos etc in a folder that has a long-unguessable random url. You can then link to the content in your code using the 'static' folder name. The customer's content will always be in that folder and accessible if they log in or not. The advantage of this compared to 1 is that your framework does not have to boot for every image or video.
-
Have all the content hidden away - possibly in the storage folder. When the user logs in, create a temporary symbolic link between their public folder and their folder in storage. Keep a note of the link in the session. Use the link in all gallery etc rather than the static code used in (2) above. Once they log out the code will no longer be valid, and you can delete the symbolic link on logout or have a job to tidy it up periodically.
Please or to participate in this conversation.