Re: sorting files

From: Date: Mon, 26 May 2003 02:15:06 +0000
Subject: Re: sorting files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148949@lists.php.net to get a copy of this message
Instead of echoing straight from the opendir, add them all to an array, then sort the array, then print from the array. <table> <tr> <? // get array of files $dir = 'files'; $fileHandle = opendir($dir); while ($myFile = readdir($fileHandle)) { if (is_file($dir.'/'.$myFile)) { $myFileArray[] = $myFile; } } closedir($fileHandle); // sort and reset the array asort ($myFileArray); reset ($myFileArray); // print <td>'s foreach($myFileArray as $k => $fileName) { echo "<td><a href='files/{$fileName}' target='_blank'>{$fileName}</a></td>"; } ?> </tr> </table> Justin on 25/05/03 8:32 AM, zavaboy (zavaboy@comcast.net) wrote: > My code: > ---------------------------------------------------------------------------- > ------------------- > $Open = opendir ("files"); > while ($Files = readdir ($Open)) { > $Filename = "files/" . $Files; > if (is_file ($Filename)) { > $Size = filesize ("files/$Files"); > echo "<td><a href=files/$Files > target=_blank>$Files</a><br>\n"; > } > } > closedir ($Open); > ---------------------------------------------------------------------------- > ------------------- > I want it to print out the files alphabetically. > >

« previous php.general (#148949) next »