我得到了一个相当奇怪的错误
file_get_contents('/var/www/site/config/../runtime/cookies/1a8dd816aafc1118dc5cbf7fd0263f20/cookie.txt'): failed to open stream: No such file or directory
所以我将代码更改为:
if (file_exists($cookie_file)) {
echo file_get_contents($cookie_file);
} else {
echo "$cookie_file does not exist\n";
}
它输出:
/var/www/site/config/../runtime/cookies/1a8dd816aafc1118dc5cbf7fd0263f20/cookie.txt does not exist
如果我这样做在命令行中
cat /var/www/site/config/../runtime/cookies/1a8dd816aafc1118dc5cbf7fd0263f20/cookie.txt
它使文件很好
权限也很好:
ls -lrt /var/www/site/config/../runtime/cookies/1a8dd816aafc1118dc5cbf7fd0263f20/cookie.txt
-rwxrwxrwx. 1 apache apache 391 Feb 11 16:27 /var/www/site/config/../runtime/cookies/1a8dd816aafc1118dc5cbf7fd0263f20/cookie.txt
所以是的,我对它为何不能阅读明显存在的文件感到困惑。
有什么想法吗?
答案 0 :(得分:0)
使用realpath
扩展绝对路径的相对路径。路径中..
和config
之间的runtime
表示其相对值,而file_get_contents
需要绝对值。