• PHP Video Tutorials

PHP - Function is_dir()



The is_dir() function can check whether the specified file is a directory. This function can return true if the directory exists.

Syntax

bool is_dir ( string $filename )

This function can tell whether the given filename is a directory.

Example-1

<?php
   $file = "/PhpProject/php";
   if(is_dir($file)) {
      echo ("$file is a directory");
   } else {
      echo ("$file is not a directory");
   }
?>

Output

/PhpProject/php is a directory

Example-2

<?php
   var_dump(is_dir("/PhpProject/simple.txt"));
   var_dump(is_dir("/PhpProject/php"));
   var_dump(is_dir("..")); 
?>

Output

bool(false)
bool(true)
bool(true)
php_function_reference.htm
Advertisements