简体   繁体   English

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

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

I am having an issue where file_exists returns false and is_file returns true. 我遇到的问题是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")); 

The output is: 输出是:

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)
}

I imagine I have done something wrong in the configuration, but haven't quite figured out what it is. 我想我在配置上做错了什么,但还没弄清楚它是什么。

What is even more exciting is that despite file_exists not working fread(fopen('/home/www/public_html/index.html','r'), filesize('/home/www/public_html/index.html')) does return the contents of the file. 更令人兴奋的是,尽管file_exists没有工作fread(fopen('/home/www/public_html/index.html','r'), filesize('/home/www/public_html/index.html'))返回文件的内容。

See the warning on file_exists() : 请参阅file_exists()上的警告:

This function returns FALSE for files inaccessible due to safe mode restrictions. 对于因安全模式限制而无法访问的文件,此函数返回FALSE However these files still can be included if they are located in safe_mode_include_dir . 但是,如果这些文件位于safe_mode_include_dir则仍可以包含这些文件。

The is_file() function doesn't seem to have this restriction. is_file()函数似乎没有此限制。

Weird, here are a few options to check from the manual: 很奇怪,这里有几个选项可以从手册中查看:

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

Or this maybe: 或者这可能是:

 Warning 

This function returns FALSE for files inaccessible due to safe mode restrictions. 对于因安全模式限制而无法访问的文件,此函数返回FALSE。 However these files still can be included if they are located in safe_mode_include_dir. 但是,如果这些文件位于safe_mode_include_dir中,则仍可以包含这些文件。

Those are the only things I can think of that might be effecting it. 这些是我能想到的唯一可能影响它的东西。 Not sure if you tried that or not, but worth a shot. 不确定你是否尝试过,但值得一试。

UPDATE UPDATE

How about the file flags? 文件标志怎么样? From the shell (if you have shell access) can you do an ls -alh /home/www/public_html | grep index.html 从shell(如果你有shell访问权限)你可以做一个ls -alh /home/www/public_html | grep index.html ls -alh /home/www/public_html | grep index.html and make sure that a flag isn't set weird on it? ls -alh /home/www/public_html | grep index.html并确保标志没有设置怪异吗?

UPDATE 2 更新2

The problem is that the directory permissions were set so the owner could not view the directory contents. 问题是目录权限已设置,因此所有者无法查看目录内容。 It is explained further in the comments 评论中进一步解释了这一点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM