Example 2. PHP 4 alternatives to scandir()
<?php
$dir = "/tmp";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
rsort($files);
print_r($files);
?>
Outputs something like:
Array
(
[0] => .
[1] => ..
[2] => bar.php
[3] => foo.txt
[4] => somedir
)
Array
(
[0] => somedir
[1] => foo.txt
[2] => bar.php
[3] => ..
[4] => .
)
Tip: You can use a URL as a filename with this function
if the fopen wrappers have been enabled. See fopen() for
more details on how to specify the filename and Appendix
J for a list of supported URL protocols.
See also opendir(), readdir(), glob(), is_dir(), and sort().
|