Create a new directory iterator from a path and list contents of the directory containing the script in PHP

Description

The following code shows how to create a new directory iterator from a path and list contents of the directory containing the script.

Example


<?php//  w w w.  j  av a 2  s  .  c om
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot()) {
        var_dump($fileinfo->getFilename());
    }
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




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