sort by date array help ... [urgent]
Posted: Sun Aug 16, 2009 3:22 pm
I have the following script which generated xml for me, I need a way though so the first <image> node is the newest image, and the last node is the oldest. so instead of it doing it via filename I would like to-do it by the date it was last touched. I plan on uploading images and upon running this script I want the most recently uploaded ones at the top...I know I have to use the filemtime function to get the time of all the files in the array, but I'm still unsure how to sort them before it gets to this line here: $play_list .= "<image Thumb=\"$file_tmb\" Large=\"$file_img\"></image>\n"; ... i've tried my darnedest for the past day and I just can't get it 
Code: Select all
<?php
$dir = '../galleries/music/';
$file_ext = "img.jpg";
$play_list = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
$play_list .= "<content>\n";
$play_list .= "<gallery>\n";
// Open directory, read contents and add to file_list if correct file_type
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
$name_array = explode('_', $file);
if ($name_array[1] == $file_ext) {
$file_img = "$file";
$file_tmb = str_replace("_img", "_tmb", "$file");
$play_list .= "<image Thumb=\"$file_tmb\" Large=\"$file_img\"></image>\n";
}
}
}
closedir($dh);
$play_list .= "</gallery>\n";
$play_list .= "</content>\n";
$wdir = ''.$dir.'images1.xml';
$f=fopen("$wdir","w") or die("Could not open and empty the file");
fwrite($f,$play_list) or die("Could not write to the file");
fclose($f) or die ("Could not close the resource");
}
}
?>