• PHP Video Tutorials

PHP - Function readdir()



Syntax

string readdir ( resource $dir_handle );

Definition and Usage

It returns the filename of the next file from the directory. The filenames are returned in the order in which they are stored by the filesystem.

Parameters

Sr.No Parameter & Description
1

dir_handle(Required)

The directory handle resource previously opened with opendir().

Return Value

It returns the filename on success, or FALSE on failure.

Example

Following is the usage of this function −

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

This will produce following result −

filename: .
filename: ..
filename: logo.gif
filename: mohd.gif
php_function_reference.htm
Advertisements