simonp Posted September 25, 2009 Share Posted September 25, 2009 I'm using the small bit of code below to show a directory listing of the files in a single folder but I want to be able to sort the files into alphabetical order. I believe this involves putting the output into an array and then showing the sorted array but I've no idea how to do this. Any help greatly appreciated. <?php $dir = new DirectoryIterator( '/home/'); foreach($dir as $file ) { if(!$file->isDot() && !$file->isDir()) { echo "<br><br>FileName: ".$file->getFilename(); echo "<br>Size: ".number_format(($file->getSize()/1024),2)." Kb"; echo "<br>Uploaded: ".date("D d M Y H:i:s",$file->getCTime()); } } ?> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted September 26, 2009 Share Posted September 26, 2009 <?php $dir = new DirectoryIterator( '/home/'); function mySort($a,$b) { $x = $a[0]; $y = $b[0]; if (strcmp($x,$y) < 0) return -1; elseif (strcmp($x,$y) === 0) return 0; else return -1; } $files = array(); foreach($dir as $file ) { if(!$file->isDot() && !$file->isDir()) { $files[] = array($file->getFilename(),number_format($fuke->getSize() / 1024,2),date("D d M Y H:i:s",$file->getCTime())); } } usort($files,'mySort'); print_r($files); ?> sorry went about it all wrong found an easier solution, read the above code, made it in notepad++ so it SHOULD work more than definately Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.