Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

closedir()

Example

Open a directory, read its contents, and then close it.

<?php
$dir = “/images/”;

// Open a directory, and read its contents
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while (($file = readdir($dh)) !== false){
      echo “filename:” . $file . “<br>”;
    }
    closedir($dh);
  }
}
?>

Result:

filename: cat.gif
filename: dog.gif
filename: horse.gif

Definition and Usage

The closedir() function closes an open directory handle.

Syntax

closedir(dir)

Parameter Values

Parameter

Description

dir

Optional. Specifies the directory handle resource previously opened with opendir(). If not provided, the function assumes the last directory handle opened by opendir().

Technical Details

 

Return Value:

PHP Version:

4.0+