List file name with dir() in PHP

Description

The following code shows how to list file name with dir().

Example


/*from   w ww . j  a  v a 2 s  .c o m*/
<?php
    $d = dir(getcwd());

    echo "Handle: " . $d->handle . "<br>";
    echo "Path: " . $d->path . "<br>";

    while (($file = $d->read()) !== false){
        echo "filename: " . $file . "<br>";
    }
    $d->close();
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




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