Monday, 26 August 2013

PHP Function rewinddir()

Syntax

void rewinddir ( resource $dir_handle );

Definition and Usage

Resets the directory stream indicated by dir_handle to the beginning of the directory.

Paramters

ParameterDescription
dir_handleRequired.The directory handle resource previously opened with opendir().

Return Value

Returns the filename 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 =rewinddir($dir)) !== false)
{
  echo "filename: " . $file . "<br />";
}
rewinddir($dir)
//List once again files in images directory
while (($file =rewinddir($dir)) !== false)
{
  echo "filename: " . $file . "<br />";
}
closedir($dir);
?> 
This will produce following result:
filename: .
filename: ..
filename: logo.gif
filename: mohd.gif
filename: .
filename: ..
filename: logo.gif
filename: mohd.gif

No comments:

Post a Comment