Home  >  Article  >  Backend Development  >  PHP is_file、file_exists、is_dir总结

PHP is_file、file_exists、is_dir总结

angryTom
angryTomforward
2019-10-14 17:39:532392browse

1. is_file() function (recommended learning: PHP video tutorial)

is_file - Determine whether the given file name is a normal File

Usage method

bool is_file ( string $filename )
// 注意事项
// 因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果 。

Return value

If the file exists and is a normal file, it returns TRUE, otherwise it returns FALSE

2. file_exists() function

file_exists — Check whether a file or directory exists

Usage method

bool file_exists ( string $filename )
// 注意事项
// 因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果 。

Return value

If the file specified by filename Returns TRUE if the directory exists, otherwise returns FALSE.

3. is_dir() function

is_dir--Check whether the specified file is a directory.

Usage

bool is_dir ( string $filename )

Return value

Returns true if the file name exists and is a directory. If file is a relative path, its relative path is checked against the current working directory.

4. Summary

file_exists = is_dir is_file

is_file only determines whether the file exists;

file_exists determines whether the file exists or whether the directory exists;

is_dir determines whether the directory exists

after searching some related Data and performance analysis, during use

When the file exists, is_file is N times faster than file_exists;

When the file does not exist, is_file is slower than file_exists;

The above is the detailed content of PHP is_file、file_exists、is_dir总结. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.whmblog.cn. If there is any infringement, please contact admin@php.cn delete