note 80161 rejected from function.DirectoryIterator-isFile by nlopess
| From: | nlopess@php.net | Date: | Wed, 02 Jan 2008 10:43:14 +0000 |
| Subject: | note 80161 rejected from function.DirectoryIterator-isFile by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134656@lists.php.net to get a copy of this message | ||
Note Submitter: leland dot michael at gmail dot com
----
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'> </td>
<td width='20%' class='titlebar'> </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> </td>";
$newrow .= "<td> </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;
}
}
?>