Hi,
The script below sorts mp3's in a folder after date and name. I have a problem with some files not being echoed if I try to sort decending. This happens if a change the functions below to < instead of >. I wonder why, and how I can make the script to correctly sort decending?
<style type="text/css"> a:link { text-decoration: none; } table { border-collapse: collapse; } td { border: 1px dotted; } </style>
<?php
// Variables
$dir = glob("*.mp3");
$sort = $_GET['sort'];
echo "<a href=../>Back</a> | <a href=../2014>2014</a> | <b><a href=../".basename(__DIR__).">".basename(__DIR__)."</a></b></p>";
// Functions for sorting each table column title
function sort_name($a,$b) { return $a > $b; }
function sort_size($a,$b) { return filesize($a) > filesize($b); }
function sort_time($a,$b) { return filemtime($a) > filemtime($b); }
// Checks wich table column title is selected
if ($sort=='name') { usort($dir, "sort_name"); }
elseif ($sort=='size') { usort($dir, "sort_size"); }
elseif ($sort=='time') { usort($dir, "sort_time"); }
else { usort($dir, "sort_time"); }
// Table
echo "<table>";
echo "<tr>";
$titles = array('nr','name','size','date','time');
foreach($titles as $title) {
if ($title==$sort) { echo "<td bgcolor=lightgreen> <b><a href=index.php?sort=$title>".$title."</a></b> </td>"; }
elseif ($title=='nr') { echo "<td bgcolor=lightblue> ".ucfirst($title)." </td>"; }
elseif ($title=='time'){ echo "<td bgcolor=lightblue> ".ucfirst($title)." </td>"; }
else { echo "<td bgcolor=lightblue> <a href=index.php?sort=$title>".ucfirst($title)."</a> </td>"; }
}
echo "</tr>";
// Table content
for($i=1; $i<count($dir); $i++) {
echo "<tr>";
echo "<td> " . $i . " </td>";
echo "<td> <a href=" . rawurldecode($dir[$i]) . ">" . $dir[$i] . "</a> </td>";
echo "<td> " . round(filesize($dir[$i])/(1024)/(1024),1) . " MB </td>";
echo "<td> " . date("d.m.Y", filemtime($dir[$i])) . " </td>";
echo "<td> " . date("H:i:s", filemtime($dir[$i])) . " </td>";
echo "</tr>";
}
echo "</table><br>";
?>