PHP | file_exists 函数
Lasted 2021-01-01 14:04:50
file_exists 函数检测文件或目录是否存在。
对于大于 2GB 的文件,由于 PHP 的整数类型是带符号的,在使用 32 位整数的平台,可能会产生意外结果。
在 Windows 中要用 //computername/share/filename 或者 \\computername\share\filename 来检查网络中的共享文件。
函数定义
    file_exists ( string $filename ) : bool
  
  // 源文件位于:ext/standard/filestat.c
# 函数定义
...
RETURN_BOOL(VCWD_ACCESS(local, F_OK) == 0);
  参数
- checkfilename - 文件或目录的路径。
 
返回值
- checkstring - 文件或目录存在则返回 true,否则返回 false。
 
示例1: - 使用 file_exists() 函数检测文件或目录是否存在。
<?php
/**
 * PHP 使用 file_exists() 函数检测文件或目录是否存在。
 *
 * @since Version 1.0.0
 * @filesource
 */
// 文件路径
$filename = 'foo.txt';
// 检测文件是否存在
if(file_exists($filename)) {
  echo "The file exists";
}
  The file exists