PHP:is_file()和file_exists()对同一个文件返回不同的结果


PHP:is_file() and file_exists() return different results on same file

我有一个问题,file_exists返回false, is_file返回true。

echo(getmygid()." = gid'n"); //501
echo(getmyuid()." = uid'n"); //501
echo(posix_getgid()." = pgid'n"); //501
echo(posix_getuid()." = puid'n"); //501
var_dump(file_exists("/home/www/public_html/")); //bool(true)
var_dump(file_exists("/home/www/public_html/index.html")); //bool(false)
var_dump(is_file("/home/www/public_html/index.html")); //bool(true)
var_dump(stat("/home/www/public_html/index.php")); 

输出为:

501 = gid
501 = uid
501 = pgid
501 = puid
bool(true)
bool(false)
bool(true)
array(26) {
  [0]=>
  int(51712)
  [1]=>
  int(58055)
  [2]=>
  int(33197)
  [3]=>
  int(1)
  [4]=>
  int(501)
  [5]=>
  int(501)
  [6]=>
  int(0)
  [7]=>
  int(473)
  [8]=>
  int(1323573973)
  [9]=>
  int(1323573973)
  [10]=>
  int(1323574039)
  [11]=>
  int(4096)
  [12]=>
  int(8)
  ["dev"]=>
  int(51712)
  ["ino"]=>
  int(58055)
  ["mode"]=>
  int(33197)
  ["nlink"]=>
  int(1)
  ["uid"]=>
  int(501)
  ["gid"]=>
  int(501)
  ["rdev"]=>
  int(0)
  ["size"]=>
  int(473)
  ["atime"]=>
  int(1323573973)
  ["mtime"]=>
  int(1323573973)
  ["ctime"]=>
  int(1323574039)
  ["blksize"]=>
  int(4096)
  ["blocks"]=>
  int(8)
}

我想我在配置中做错了什么,但还没有完全弄清楚是什么。

更令人兴奋的是,尽管file_exists不能工作,fread(fopen('/home/www/public_html/index.html','r'), filesize('/home/www/public_html/index.html'))还是返回了文件的内容。

奇怪,这里有几个选项可以从手册中检查:

Note: The results of this function are cached. See clearstatcache() for more details.

或者这个:

Warning

对于由于安全模式限制而无法访问的文件,此函数返回FALSE。但是,如果这些文件位于safe_mode_include_dir目录下,它们仍然可以被包含。

这些是我能想到的唯一可能影响它的事情。不知道你有没有试过,但值得一试。

文件标志呢?从shell(如果你有shell访问),你可以做一个ls -alh /home/www/public_html | grep index.html,并确保一个标志没有设置奇怪吗?

更新2

问题是设置了目录权限,因此所有者无法查看目录内容。在

注释中有进一步的解释

参见file_exists():

对于由于安全模式限制而无法访问的文件,该函数返回FALSE。但是,如果这些文件位于safe_mode_include_dir中,则仍然可以包含它们。

is_file()函数似乎没有这个限制。