PHP | is_dir( ) Function
Last Updated :
07 Jun, 2018
Improve
The is_dir() function in PHP used to check whether the specified file is a directory or not. The name of the file is sent as a parameter to the is_dir() function and it returns True if the file is a directory else it returns False.
Syntax:
php
Output:
php
Output:
is_dir($file)Parameters Used: The is_dir() function in PHP accepts only one parameter.
- $file : It is a mandatory parameter which specifies the file.
- An E_WARNING is emitted on failure.
- The result of this function are cached and therefore the clearstatcache() function is used to clear the cache.
- is_dir() function returns false for non-existent files.
<?php
$myfile = "user/home/documents/gfg";
// checking whether a file is directory or not
if (is_dir($myfile))
echo ("$myfile is a directory");
else
echo ("$myfile is not a directory");
?>
user/home/documents/gfg is a directoryProgram 2
<?php
$myfile = "https://www.geeksforgeeks.org";
// checking whether a file is directory or not
if (is_dir($myfile))
echo ("$myfile is a directory");
else
echo ("$myfile is not a directory");
?>
https://www.geeksforgeeks.org is not a directoryReference: http://php.net/manual/en/function.is-dir.php