Home > Article > Backend Development > Guide to using is_dir() function in PHP, guide to using is_dir_PHP tutorial
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 against 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, output:
images is a directory
The above is the entire content of this article, I hope you all like it.