That's the only way I can think of. Here a code of mine that does it.
$path = "/path/to/file/directory/";
chdir($path);
$main = opendir($path);
while($file = readdir($main)) {
$file_array[]=$file;
}
sort($file_array);
for($arrayLoop=0;$arrayLoop <= count($file_array);$arrayLoop++){
echo"$file_array[$arrayLoop]\n";
}