I'm have a script that outputs files and folders w/ folders as a header and the files listed below. I'd like to sort them alphabetically, but can't seem to figure it out. I think I need to get them into an array. Or use scandir. Here's the code:
function getDirectory( $path = '.', $level = 0 ){
$ignore = array( '.', '..', 'index.php' );
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) ){
if( !in_array( $file, $ignore ) ){
$spaces = str_repeat( ' ', ( $level * 4 ) );
if( is_dir( "$path/$file" ) ){
echo "<strong>$spaces $file</strong><br />
";
getDirectory( "$path/$file", ($level+1) );
} else {
echo "$spaces <a href=\"$path/$file\">$file</a><br />
";
}
}
}
closedir( $dh );
}
getDirectory( "." );