1

I want to deny access to particular directory to show list of files in it in the browser. For example, If I go to the url, localhost/myproject/assets, it will show all the list of files in it, I want to deny that. And also if logged in user access specific file in it, for ex : localhost/myproject/assets/uploads/img/1.jpg then it should be accessible. Also how to deny access to a localhost/myproject/assets/uploads/img/1.jpg if that 1.jpg is uploaded by some other user.

I'm new to laravel ,Any help is much appreciated. thanks

Aamir
  • 2,173
  • 1
  • 29
  • 58
  • Which web server are you running your app with? It would also be helpful to see you web servers configuration file. – henrik Jun 17 '16 at 09:15
  • Using Apache webserver. – Aamir Jun 17 '16 at 09:44
  • About your last question: You can't, at least not when you place the files in a directory that is publicly accessible through the web-server. The only way to achieve that is to move the files to a place that is not accessible and serve them through php. – jeroen Jun 21 '16 at 07:35

2 Answers2

1

You could add the following to the .htaccess file in the folder. This might help.

Options -Indexes

You cannot deny the access to the jpg uploaded by another user.

-1

If you are using Apache, you can place a .htaccess file in the folder you want to block. Then you can use deny from all to block all requests to that folder.

This works because a .htaccess file can be in every directory in your web root, and only cares about the directory it is in and its subdirectories.

See this answer.

Community
  • 1
  • 1
16patsle
  • 513
  • 7
  • 12