Re: sorting files

From: Date: Tue, 27 May 2003 01:03:57 +0000
Subject: Re: sorting files
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-149022@lists.php.net to get a copy of this message
Yeah, I got that idea and got it working... Thanks anyway! "Justin French" <justin@indent.com.au> wrote in message news:BAF7C3DA.27C3F%justin@indent.com.au... > 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 (#149022) next »