PHP file_exists is_dir is_file 三者的区别

发表在 开发 共有 0 条评论

PHP的file_exists = is_dir + is_file

当文件存在时,is_file函数比file_exists函数速度快大约15倍,当文件不存在时,两者速度相当。

当文件目录存在时,is_dir()比file_exists()快18倍,不存在时两者效率相当。

如果要判断目录是否存在,请使用函数 is_dir(directory)
如果要判断文件是否存在,请使用函数 is_file(filepath)
判断目录或文件是否存在,请使用函数 file_exists($path)
评论已关闭