Justice
11-04-2004, 06:04 PM
Right now, I have a piece of code set up to display a list of mp3's in a directory, but I can't control the order it's displayed in yet. I want the files to be listed from newest to oldest.
<?php
$cnt = 1;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !is_dir($file) && fnmatch("*.mp3", $file)) {
$desc = strtr($file, "_", " ");
$desc = str_replace(".mp3", '', $desc);
$desc = ucwords(strtolower($desc));
if(fmod($cnt, 2) == 0) $color = "#E2E2E2";
else $color = "#FFFFFF";
echo "<tr><td bgcolor='$color'><a href='$file'>$desc</a></td><td bgcolor='$color' align='center'>"
.round((filesize($file) / 1024), 0)." KB</td><td bgcolor='$color' align='center'>"
.date ("m.d.Y", filemtime($file))."</td></tr>";
$cnt++;
}
}
closedir($handle);
}
?>
Is there a way to edit that code to control the list, or do I need to use a completely different approach?
Thanks in advance for any help.
<?php
$cnt = 1;
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !is_dir($file) && fnmatch("*.mp3", $file)) {
$desc = strtr($file, "_", " ");
$desc = str_replace(".mp3", '', $desc);
$desc = ucwords(strtolower($desc));
if(fmod($cnt, 2) == 0) $color = "#E2E2E2";
else $color = "#FFFFFF";
echo "<tr><td bgcolor='$color'><a href='$file'>$desc</a></td><td bgcolor='$color' align='center'>"
.round((filesize($file) / 1024), 0)." KB</td><td bgcolor='$color' align='center'>"
.date ("m.d.Y", filemtime($file))."</td></tr>";
$cnt++;
}
}
closedir($handle);
}
?>
Is there a way to edit that code to control the list, or do I need to use a completely different approach?
Thanks in advance for any help.
