scandir() for PHP4
Written by Cory S.N. LaViska on March 28th, 2008
A function that lets you use scandir() in versions prior to PHP5.
This function is very similar to PHP5’s scandir(), except that it does not support the $context parameter. To sort in descending order , set $sorting_order to 1.
<?php
if( !function_exists('scandir') ) {
function scandir($directory, $sorting_order = 0) {
$dh = opendir($directory);
while( false !== ($filename = readdir($dh)) ) {
$files[] = $filename;
}
if( $sorting_order == 0 ) {
sort($files);
} else {
rsort($files);
}
return($files);
}
}
?>
if( !function_exists('scandir') ) {
function scandir($directory, $sorting_order = 0) {
$dh = opendir($directory);
while( false !== ($filename = readdir($dh)) ) {
$files[] = $filename;
}
if( $sorting_order == 0 ) {
sort($files);
} else {
rsort($files);
}
return($files);
}
}
?>
The purpose of this function is to enable the use of scandir() in PHP versions prior to PHP5. It is “future compatible”, so you don’t have to worry about anything breaking when you upgrade to PHP5.


Comments
#1 Daniel on Mar 28th, 2008
#2 John on Mar 28th, 2008
#3 Cory S.N. LaViska on Mar 28th, 2008