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

PHP is_file、file_exists、is_dir总结

angryTom
Release: 2023-04-07 15:38:02
forward
2459 people have browsed it

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 以上的文件,一些文件系统函数可能返回无法预期的结果 。
Copy after login

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 以上的文件,一些文件系统函数可能返回无法预期的结果 。
Copy after login

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 )
Copy after login

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!

Related labels:
source:www.whmblog.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template