Home > Article > Backend Development > PHP function is_dir()
php provides the built-in function is_dir to check whether the incoming path parameter is a directory, and returns true if it is a directory. That is to say, if the parameter passed in is a file or does not exist, it will be false, so the current parameter cannot be said to be either a folder or a file. Another thing to note is that parameters support relative paths and absolute paths. This article will introduce it in detail and hope it will be helpful to everyone.
Function: is_dir()
Function: Determine whether the given file name is a directory
Description:
bool is_dir ( string $ filename )
Returns TRUE if the filename exists and is a directory.
If filename is a relative path, its relative path is checked according to the current working directory.
Note: The result of this function will be cached. See clearstatcache() for more information.
Example 1
<? var_dump(is_dir('a_file.txt')) . "\n"; var_dump(is_dir('bogus_dir/abc')) . "\n"; var_dump(is_dir('..')); //one dir up ?>
The above example will output:
bool(false)
bool( false)
bool(true)
Example 2
<?php $file = "images"; if(is_dir($file)) { echo ("$file is a directory"); } else { echo ("$file is not a directory"); } ?>
Output:
If the images directory exists, Then the output:
images is a directory
Related recommendations:
##PHP file reading fread, fgets, fgetc, file_get_contents and file Function usage example code
php file type judgment example code
A brief introduction PHP file lock and process lock
The above is the detailed content of PHP function is_dir(). For more information, please follow other related articles on the PHP Chinese website!