PHP Function Reference

PHP Directory - close() Method



The PHP Directory::close() method closes the directory stream.

This method is same as closedir() function, only dir_handle defaults to $this->handle.

Syntax

public Directory::close()

Parameters

No parameter is required.

Return Value

No value is returned.

Example: Directory::close() example

The example below shows the usage of Directory::close() method.

<?php
$dir = "/temp/images";

//opens the directory, and read its contents
if (is_dir($dir)){
  if ($d = dir($dir)){
    
    //reading all entry from directory handle
    while (($file = $d->read()) !== false){
      echo "File Name: ".$file."\n";
    }
    
    //closing the directory handle
    $d->close();
  }
}
?>

The output of the above code will be:

File Name: fig1.png
File Name: fig2.png
File Name: Photo.jpg
File Name: .
File Name: ..
File Name: error.jpeg

❮ PHP Date and Time Reference