阻止用户下载特定目录中的文件


Prevent users from downloading files in a specific directory

我的网站是用PHP编写的。库文件存储在一个名为"库"的目录中。

在我的php中,我通过访问库文件

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

但是,如果用户键入

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

他们可以下载源代码。我该如何防止这种情况发生?

在root/library/.htaccess下创建.htacccess文件并写入以下

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