file_exists -- 检查文件或目录是否存在
说明
bool file_exists ( string filename )
如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE。
在 Windows 中要用 //computername/share/filename 或者 \computernamesharefilename 来检查网络中的共享文件。
例子 1. 测试一个文件是否存在
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>
注: 本函数的结果会被缓存。更多信息参见 clearstatcache().