PHP Tutorial - PHP is_dir() Function






Definition

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

Syntax

PHP is_dir() Function has the following syntax.

is_dir(file)

Parameter

ParameterIs RequiredDescription
fileRequired.File to check

Return

This function returns TRUE if the directory exists.

Note

The result of this function are cached. Use clearstatcache() to clear the cache.





Example

is_dir() returns true if the string parameter is a directory.

For example, to check whether it is a directory:


<?PHP/*from   ww w  .  j a v a2 s. co m*/
      $filename = 'c:\boot.ini'; // Windows
      $filename = '/etc/passwd'; // Unix

      if (is_dir($filename)) {
             print 'is Directory!';
      } else {
             print 'is not a Directory!';
      }
?>

The code above generates the following result.