我收到一个相当奇怪的错误
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
所以,是的,我很困惑为什么它不会读取清楚存在的文件。
有什么想法吗?
使用realpath
将相对路径扩展为绝对路径。路径中config
和runtime
之间的..
表示其相对,而file_get_contents
则要求绝对。