This example will list the contents of the directory containing the script.
<?php
$dir = new DirectoryIterator(dirname(__FILE__));
foreach ($dir as $fileinfo) {
echo $fileinfo;
}
?>
The above example will output
something similar to:
.
..
apple.jpg
banana.jpg
index.php
pear.jpg