PHP - Function closedir()


Advertisements


Syntax

void closedir ( resource $dir_handle );

Definition and Usage

Closes the directory stream indicated by dir_handle. The stream must have previously been opened by opendir().

Parameters

Parameter Description
directory Required. The directory handle resource previously opened with opendir().

Return Value

Returns TRUE on success or FALSE on failure.

Example

Following is the usage of this function −

<?php
   //Open images directory
   $dir = opendir("/var/www/images");
   
   //List files in images directory
   while (($file = readdir($dir)) !== false)
   {
      echo "filename: " . $file . "<br />";
   }
   closedir($dir);
?> 

This will produce the following result −

filename: .
filename: ..
filename: logo.gif
filename: mohd.gif

php_function_reference.htm