English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP is_dir() Function Usage and Example

PHP Filesystem Reference Manual

The is_dir() function can check if the specified file is a directory. If the directory exists, this function can return true.

Syntax

bool is_dir ( string $filename )

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

Example1

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

Output Result

/PhpProject/php is a directory

Example2

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

Output Result

bool(false)
bool(true)
bool(true)

PHP Filesystem Reference Manual