PHP is_dir() function

Definition and Usage

The is_dir() function checks if the specified file is a directory.

Syntax

is_dir(file)
Parameter Description
file Required. Specifies the file to be checked.

Description

If the filename exists and is a directory, it returns true. If file If it is a relative path, check its relative path according to the current working directory.

Tips and Comments

Note:The result of this function will be cached. Please use clearstatcache() to clear the cache.

Example

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

Output:

images is a directory