When I use file_get_contents
on a path like /a/path/to/a/../file.php
, it gets the content just fine. If I call file_exists
first (or is_file
or realpath
), the return values indicate that the file does not exist. What seems to be the issue?
Edit: Here is some additional information condensed from comments to answers:
- I am running Mac OS X 10.9 with php 5.5.6, so safe mode should not be an issue (it was removed in version 5.4)
- I tried clearing the file cash by calling
clearstatcache(true, $dir1)
- The file in question is 362 bytes in size, but I reproduced this issue with several different files in a medley of locations.
open_basedir
is commented out in the php.ini- The file is local (the first file I tried was in the same directory as the script)
- The issue exists in the command line (phpUnit) and in the browser.
- The permissions on the file in questions are
-rwxrwxrwx
(I sudo-chmod-777ed the file)
This is a code snippet that creates the behavior:
$dir1 = '/a/path/to/a/../file.php';
$dir2 = '/a/path/to/file.php';
echo "File content dir1:\n";
echo file_get_contents($dir1);
echo "\ndir1 exists: ".(int)file_exists($dir1);
echo "\n\nFile content dir2:\n";
echo file_get_contents($dir2);
echo "\ndir2 exists: ".(int)file_exists($dir2);
the output is:
File content dir1:
The actual content of the file. I promise!
dir1 exists: 0
File content dir2:
The actual content of the file. I promise!
dir2 exists: 1