Get file name of current DirectoryIterator item in PHP

Description

The following code shows how to get file name of current DirectoryIterator item.

Example


//  w ww .ja v a2 s.  co m
//This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
    echo $fileinfo->getFilename() . "\n";
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




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