2011-11-26 44 views

回答

1

您可以轻松访问public_html文件夹外的任何文件,只需确保文件可供Web服务器用户访问。例如:

$ls -l 
total 8 
-rw-r--r-- 1 www-data www-data 12 Nov 26 13:08 test.txt 
drwxr-xr-x 2 www-data www-data 4096 Nov 26 13:11 www 

而下面的PHP脚本正在读的test.txt:

<?php 

$file = $_SERVER['DOCUMENT_ROOT'] . "/../test.txt"; // relative path 
//$file = "/opt/nguyen/test.txt"; //absolute path 
$contents = file($file); 
$string = implode($contents); 

echo $string; 

?> 

你也可以把你的文件在您的public_html文件夹,并拒绝了的.htaccess访问:

<Files config.inc.php> 
    order allow,deny 
    deny from all 
</Files> 
相关问题