file_exists—检查文件或目录是否存在
说明
boolfile_exists(string$filename
)
检查文件或目录是否存在。
参数
filename
文件或目录的路径。
在 Windows 中要用//computername/share/filename或者\\computername\share\filename来检查网络中的共享文件。
返回值
如果由filename
指定的文件或目录存在则返回TRUE
,否则返回FALSE
。
Note:因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果 。
范例
Example #1 测试一个文件是否存在
<?php$filename=/path/to/foo.txt;if(file_exists($filename)){echo"Thefile$filenameexists";}else{echo"Thefile$filenamedoesnotexist";}?>