How to determine whether the path is a folder or a file in php

青灯夜游
Release: 2023-03-13 06:12:01
original
2416 people have browsed it

In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file. The syntax "if(is_dir($file)){echo "is a folder"; }else if(is_file($file)){echo "is a file"}".

How to determine whether the path is a folder or a file in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php determines whether the path is a folder or File

In PHP, you can use the if statement and the is_dir() and is_file() functions to determine whether the path is a folder or a file.

  • The is_dir() function can check whether the specified file is a directory. If the directory exists, this function returns TRUE.

  • The is_file() function can check whether the specified file is a regular file. If the file is a regular file, this function returns TRUE.

Implementation code:

Copy after login

Output result:

How to determine whether the path is a folder or a file in php

If $f# If the value of ##ile is changed to "img", it will output:

How to determine whether the path is a folder or a file in php

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of How to determine whether the path is a folder or a file 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 [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!