note 80161 added to function.DirectoryIterator-isFile

From: Date: Wed, 02 Jan 2008 01:54:56 +0000
Subject: note 80161 added to function.DirectoryIterator-isFile
Groups: php.notes 
Request: Send a blank email to php-notes+get-134650@lists.php.net to get a copy of this message
I thought I had this working but upon closer inspection I see that the multiarray sort function is only correct when I sort by filesize. Any help would be greatly appreciated... Here's the code: <?php $sortby = (isset($_GET['sortby'])) ? $_GET['sortby'] : 'file' ; foreach(new DirectoryIterator($currentdir) as $file){ if (!$file->isDot() && $file != "index.php" && substr($file,0,1) != "_"){ $dir_array[] = $file->getFilename(); $size_array[] = $file->getSize(); $time_array[] = $file->getMTime(); } } //COUNT AND SORT switch($sortby) { case "file": $index_count = count($dir_array); array_multisort($dir_array, SORT_ASC); break; case "size": $index_count = count($size_array); array_multisort($size_array, SORT_ASC); break; case "date": $index_count = count($time_array); array_multisort($time_array, SORT_DESC); break; } //LOOP THROUGH ARRAY if($showdotdot=='true') { echo " <tr> <td width='65%' class='titlebar'><div align='left'><a href='filelist2.php?newdir=$previousdir' class='titlebar'> <img src='images/back.gif' width='17' heigt='17'></a></div></td> <td width='15%' class='titlebar'>&nbsp</td> <td width='20%' class='titlebar'>&nbsp</td> </tr>"; } for($index=0; $index < $index_count; $index++){ if (is_dir($currentdir."/".$dir_array[$index])) { $newrow = "<tr>"; $newrow .= "<td><img src='images/folder.gif'> <a href='filelist2.php?newdir=$currentdir/$dir_array[$index]' class='filelist'>$dir_array[$index]</a></td>"; $newrow .= "<td>&nbsp;</td>"; $newrow .= "<td>&nbsp;</td>"; $newrow .= "</tr>"; echo $newrow; } elseif (is_file($currentdir."/".$dir_array[$index])) { $extension = strrev(substr(strrev($dir_array[$index]), 0, stripos(strrev($dir_array[$index]), '.'))); switch($extension) { case "jpg": $extimg = "images/image.gif"; break; case "mov": $extimg = "images/mov.gif"; break; default: $extimg = "images/file.gif"; break; } $newrow = "<tr>"; $newrow .= "<td><img src=".$extimg.">"; $newrow .= "<a href='$currentdir/$dir_array[$index]' class='filelist' target='_blank'>$dir_array[$index]</a></td>"; $newrow .= "<td>".number_format($size_array[$index]/1024,2)." Kb</td>"; $newrow .= "<td>".date('d M Y H:i:s', $time_array[$index])."</td>"; $newrow .= "</tr>"; echo $newrow; } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 76.87.121.13 ---- Manual Page -- http://www.php.net/manual/en/function.DirectoryIterator-isFile.php Edit -- https://master.php.net/note/edit/80161 Del: integrated -- https://master.php.net/note/delete/80161/integrated Del: useless -- https://master.php.net/note/delete/80161/useless Del: bad code -- https://master.php.net/note/delete/80161/bad+code Del: spam -- https://master.php.net/note/delete/80161/spam Del: non-english -- https://master.php.net/note/delete/80161/non-english Del: in docs -- https://master.php.net/note/delete/80161/in+docs Del: other reasons-- https://master.php.net/note/delete/80161 Reject -- https://master.php.net/note/reject/80161 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134650) next »