1// Shows us all files and directories in directory except "." and "..".
2
3foreach (new DirectoryIterator('../moodle') as $fileInfo) {
4 if($fileInfo->isDot()) continue;
5 echo $fileInfo->getFilename() . "<br>\n";
6}
1if ($handle = opendir('.')) {
2
3 while (false !== ($entry = readdir($handle))) {
4
5 if ($entry != "." && $entry != "..") {
6
7 echo "$entry\n";
8 }
9 }
10
11 closedir($handle);
12}
1<?php
2$dir = "/images/";
3
4// Sort in ascending order - this is default
5$a = scandir($dir);
6
7// Sort in descending order
8$b = scandir($dir,1);
9
10print_r($a);
11print_r($b);
12?>
1scandir ( string $directory [, int $sorting_order = SCANDIR_SORT_ASCENDING [, resource $context ]] ) : array