允许file_get_conents文件,但不允许浏览目录?

时间:2012-10-05 02:39:09

标签: php apache

在我的public_html文件夹中,我有一些代码如下:

echo file_get_contents('files/123.txt');

用户可以从子文件夹中查看文本文件。但是,是否可以使用apache通过浏览器阻止对files文件夹的传入请求?

2 个答案:

答案 0 :(得分:2)

在Apache配置中,您可以添加:

<Directory /path/to/files/>
    Order Deny,Allow
    Deny from All
</Directory>

http://httpd.apache.org/docs/2.4/mod/core.html#directory

我认为允许file_get_contents是PHP关注的问题,而不是Apache关注的问题。

但是一旦你这样做,一定要记住重启Apache!

答案 1 :(得分:0)

相关问题