Home > Article > Backend Development > How to determine whether it is a file or a folder in php
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.
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)
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)
(Learning video recommendation: php video tutorial)
Example 1:
<?php $file = "images"; if(is_dir($file)) { echo ("$file is a directory"); } else { echo ("$file is not a directory"); } ?>
Output Result:
images is a directory
Example 2:
<?php $file = "test.txt"; if(is_file($file)) { echo ("$file is a regular file"); } else { echo ("$file is not a regular file"); } ?>
Output:
test.txt is a regular file
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!