How to determine whether it is a file or a folder in php

王林
Release: 2023-03-04 17:58:02
Original
3550 people have browsed it

php method to determine whether it is a file or a folder: first use the is_dir() function to determine whether the specified file is a folder, and if so, return true; then use the is_file() function to determine whether the specified file is a folder. Regular file, returns true if it is.

How to determine whether it is a file or a folder in php

is_dir() function checks whether the specified file is a directory. If the directory exists, this function returns TRUE.

(Recommended tutorial:php graphic tutorial)

Syntax:

is_dir(file)
Copy after login

is_file() function checks whether the specified file is a regular file. If the file is a regular file, this function returns TRUE.

Grammar:

is_file(file)
Copy after login

(Learning video recommendation:php video tutorial)

Example 1:

Copy after login

Output Result:

images is a directory
Copy after login

Example 2:

Copy after login

Output:

test.txt is a regular file
Copy after login

The above is the detailed content of How to determine whether it is a file or a folder in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!