PHP closedir() Function

Definition

The closedir() function closes a directory handle.

Syntax

PHP closedir() Function has the following syntax.

closedir(dir_handle);

Parameter

ParameterIs RequiredDescription
dir_handleOptional.Directory handle resource previously opened with opendir(). If not specified, the last link opened by opendir() is used

Example

Open a directory, read its contents, then close:


<?php//w w w .j  av a2  s . co m
$dir = "/data/";

if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while (($file = readdir($dh)) !== false){
      echo "filename:" . $file . "\n";
    }
    closedir($dh);
  }
}
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions