Stanly Simon Stanly Simon - 8 days ago 4
PHP Question

How to restrict folder content listing in php

I have a web application developed in PHP.
My requirement is to block a folder which contains uploaded documents.
For example, if a user click a document link on the application, it should open
http://localhost:1987/enterprise_resource_planning/uploads/students/documents/1499866795_100_100.pdf
if a user execute below url, it should block
http://localhost:1987/enterprise_resource_planning/uploads/students/documents/
I've tried .htaccess with Deny from all, but it is blocking everything.
Any solution for this senario ?

Answer

possible solutions:

  • place a file index.html or index.php in the directory
  • define in your httpd.conf Options -Indexes
  • place that line in .htaccess

personnally I prefer the 2nd line. There hardly ever is use for automatical listing of the files to a browsing visitor.