PHP | is_dir( ) Function
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"; // checking whether a file is directory or not 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 // checking whether a file is directory or not 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
Recommended Posts:
- PHP | SplFileInfo isDir() Function
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | arc() Function
- p5.js | abs() function
- p5.js | pow() function
- p5.js | nfp() Function
- p5.js | nfc() function
- p5.js | nf() Function
- p5.js | second() function
- D3.js | d3.map.set() Function
- p5.js | nfs() Function
- PHP | max( ) Function
- D3.js | d3.lab() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



