The is_dir()
function in PHP checks whether the given filename is a directory.
is_dir(string: $name):bool
name
: This specifies the path to the file we want to check.
is_dir()
returns true
if the provided filename exists and is also a directory. Otherwise, it returns false
.
The following code shows the use of the is_dir()
function.
<?php$file = "test.txt";mkdir("documents");if(is_dir($file)){echo ("$file is a directory");}else{echo ("$file is not a directory");}echo "\n";if(is_dir("documents")){echo ("Documents is a directory");}else{echo ("Documents is not a directory");}?>
In the code above, the file test.txt
is passed to the function. Since it is not a directory, is_dir()
returns false
.
The mkdir
function makes a directory named documents
and returns true
when it is checked using the is_dir()
function.
This function produces cache output. We have to clear the cache by using the
clearstatcache()
function.
Free Resources