jagku
jagku

Reputation: 309

Prevent users from downloading files in a specific directory

My website is coded using PHP. Library files are stored in a directory called 'library'.

Within my php I access the library files by

require_once('library/myfile.php.inc'); 

However, if the user types in

http://www.example.com/library/myfile.php.inc

They are able to download the source code. How can I prevent this?

Upvotes: 0

Views: 381

Answers (1)

Nitin Kaushal
Nitin Kaushal

Reputation: 211

Create .htaccess file under root/library/.htaccess and write the following

<FilesMatch ".*">
    Order Allow,Deny
    Deny from All
</FilesMatch>

Upvotes: 1

Related Questions