如果由 filename 指定的文件或目录存在则返回
TRUE
,否则返回 FALSE
。
在 Windows 中要用 //computername/share/filename
或者
\\computername\share\filename
来检查网络中的共享文件。
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
本函数的结果会被缓存。更多信息参见 clearstatcache()。
自 PHP 5.0.0
起本函数也可被某些 URL wrapper 使用。参考附录 M, 支持的协议/封装协议列表 来看哪些 wrapper 支持
stat() 系列函数的功能。
如果因为安全模式的限制而导致不能访问文件的话,该函数会返回
FALSE
。然而,如果文件在
safe_mode_include_dir
所指定的目录内的话,仍然可以使用
include 来包含。