听起来你打开了安全模式并试图访问PHP在安全模式下运行时认为不安全的文件.
From the manual:
Warning
This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.
编辑:如果/ a / path / to / a /不是真实路径,您也可以重现此行为.例如:
$dir1 = '/realDir/realDir2/filetoinclude.php';
echo "File content dir1:\n";
echo file_get_contents($dir1); // outputs file contents
echo "\ndir1 exists: ".(int)file_exists($dir1); // outputs 1
$dir2 = '/realDir/realDir2/realDir3/../filetoinclude.php';
echo "\n\nFile content dir2:\n";
echo file_get_contents($dir2); // outputs file contents
echo "\ndir2 exists: ".(int)file_exists($dir2); // outputs 1
$dir3 = '/realDir/realDir2/NotARealDirectory/../filetoinclude.php';
echo "\n\nFile content dir3:\n";
echo file_get_contents($dir3); // outputs file contents
echo "\ndir3 exists: ".(int)file_exists($dir3); // outputs 0
这是因为file_exists需要遍历整个路径,因此它会查找丢失的目录并失败.我不确定file_get_contents到底有什么不同,我在谷歌上找不到多少,但它显然对路径的解析与file_exists的做法不同.