Open a directory, list its files, reset directory handle, list its files once again, then close in PHP

Description

The following code shows how to open a directory, list its files, reset directory handle, list its files once again, then close.

Example


/*from w w w .j  a  v a2s  .c  o m*/
<?php
   $dir = "/images/";

   // Open a directory, and read its contents
   if (is_dir($dir)){
     if ($dh = opendir($dir)){
       // List files in images directory
       while (($file = readdir($dh)) !== false){
         echo "filename:" . $file . "<br>";
       }
       rewinddir();
       // List once again files in images directory
       while (($file = readdir($dh)) !== false){
         echo "filename:" . $file . "<br>";
       }
       closedir($dh);
     }
   }
?>




















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip