在我public_html
文件夾中,我有一些像這樣的代碼:允許文件的file_get_conents,但不允許瀏覽目錄?
echo file_get_contents('files/123.txt');
用戶可以從一個子文件夾中查看的文本文件。但是,是否有可能使用apache通過瀏覽器阻止傳入的請求到files
文件夾?
在我public_html
文件夾中,我有一些像這樣的代碼:允許文件的file_get_conents,但不允許瀏覽目錄?
echo file_get_contents('files/123.txt');
用戶可以從一個子文件夾中查看的文本文件。但是,是否有可能使用apache通過瀏覽器阻止傳入的請求到files
文件夾?
在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!
雖然下面的兩個選項都可以使用,但最好的辦法是讓它們保持在Web根目錄之外。 – 2012-10-05 02:48:58