当前位置:首页> PHP教程> PHP入门
关键字
文章内容
file_exists函数
 
 
修改时间:[2008/08/27 01:07]    阅读次数:[1198]    发表者:[起缘]
 
file_exists -- 检查文件或目录是否存在

说明

bool file_exists ( string filename)

如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE

在 Windows 中要用 //computername/share/filename 或者 \\computername\share\filename 来检查网络中的共享文件。

例子 1. 测试一个文件是否存在

<?php
$filename
= '/path/to/foo.txt'
;

if (
file_exists($filename
)) {
    print
"The file $filename exists"
;
} else {
    print
"The file $filename does not exist"
;
}
?>

注: 本函数的结果会被缓存。详细信息参见 clearstatcache()

注: 本函数不能作用于远程文件,被检查的文件必须通过服务器的文件系统访问。