Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protect image directory

Tags:

symfony

I`m looking for some solution which will make my directory with pictures secured. In my page only Administrator have permission to upload the pictures. User have opportunity only to view a picture for products. I want to make directory more secured. I want to make it difficult to download all pictures from some kind of scripts.

For now I tried with .htpaccess and .htpasswd it work fine but when User trying to see the product page(where are available pictures form secured folder) htpaccess is requiring a username and password.

Is it possible to enter username and password to this directory from server side when user is watching the product page. And in case that he open a link of the picture in new window then user name and password is required?

Do you know some other solutions?

Cheers

like image 340
Kosmonaft Avatar asked Apr 11 '26 19:04

Kosmonaft


2 Answers

Don't store the images in your web folder where everyone can access them. Instead, store them outside of the web path (for example in app/data or so) and use a symfony controller to deliver them. This way you can use the symfony security component.

like image 73
Pierre Avatar answered Apr 13 '26 23:04

Pierre


In addition to good answer by @Pierre, you can use a filesystem abstraction layer. I'd recommend using Gaufrette. To integrate it with Symfony, you could use KnpGaufretteBundle.

It will give you way more flexibility as

  • using external filesystems (ex. Amazon S3, FTP, sFTP)
  • use Symfony Security component or ACL.

Everything depends on your need and your approach in the project. However, if you need some flexibility, I'd recommend try it out.

like image 43
Andrzej Ośmiałowski Avatar answered Apr 13 '26 22:04

Andrzej Ośmiałowski