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:
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.
Return Value:
It returns True if the file is a directory else it returns false.
Exceptions:
- 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.
Below programs illustrate the is_dir() function.
Program 1
<?php
$myfile = "user/home/documents/gfg" ;
if ( is_dir ( $myfile ))
echo ( "$myfile is a directory" );
else
echo ( "$myfile is not a directory" );
?>
|
Output:
user/home/documents/gfg is a directory
Program 2
<?php
if ( is_dir ( $myfile ))
echo ( "$myfile is a directory" );
else
echo ( "$myfile is not a directory" );
?>
|
Output:
https://www.geeksforgeeks.org is not a directory
Reference:
http://php.net/manual/en/function.is-dir.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Jun, 2018
Like Article
Save Article