函数名:file_exists()
适用版本:所有版本
用法:file_exists() 函数用于检查文件或目录是否存在。
语法:bool file_exists ( string $filename )
参数:
返回值:
示例:
// 检查文件是否存在
$file = 'path/to/file.txt';
if (file_exists($file)) {
echo "文件存在";
} else {
echo "文件不存在";
}
// 检查目录是否存在
$dir = 'path/to/directory';
if (file_exists($dir)) {
echo "目录存在";
} else {
echo "目录不存在";
}
注意事项: