PHP | is_dir( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report 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 <?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 <?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"); ?> Output: https://www.geeksforgeeks.org/ is not a directory Reference: https://www.php.net/manual/en/function.is-dir.php Comment More infoAdvertise with us S Shubrodeep Banerjee Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like