我写了一个PHP应用程序(可以工作),我把它移到了另一个目录。 因此,它需要从其上方的目录中获取文件,但该文件必须保持隐藏状态,即:
- 根 -
- -配置
- ---用户.xml(权限 600)
- --自由
- ----登录实用工具.php
我尝试了两种不同的获取文件的方法:
$xml = file_get_contents("../config/users.xml");
Which returns the following Error:
[13-Jun-2012 08:54:04] PHP Warning: file_get_contents(../config/users.xml) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in public_html/test/lib/loginUtil.php on line 18
和
$xml = simplexml_load_file("../config/users.xml");
which returns
[13-Jun-2012 08:56:17] PHP Warning: simplexml_load_file() [<a href='function.simplexml-load-file'>function.simplexml-load-file</a>]: I/O warning : failed to load external entity
我已经尝试使用完整的URL,并且有效,但是我必须将用户.xml文件公开(因为PHP正在执行URL请求)。
我该怎么做才能解决此问题? (感谢您的帮助)
尝试设置完整路径而不是相对路径
$path = '/var/full/path_dir/file.xml';
if(!is_file($path)){
// if this is the is output then you need to check permissions
// double check the file exists also.
// check the web service can read the file
echo "FILE NOT FOUND FOR $path";
}
else{
$xml = file_get_contents($path);
echo $xml;
}