This might me overkill for you but this is a function that I made some time ago to do this sort of thing. The output of this will give you an idea of how to deal with the output:
<?PHP
$dirInfo = sort_files_by_attrib("./", 9);
print_r($dirInfo);
?>
And here's the actual function:
<?PHP
function sort_files_by_attrib($path, $attrib, $reverse = FALSE) {
//Sorts a directory listing by various attributes:
//13 = Name
//4 = UID
//5 = GID
//7 = Size in bytes
//9 = Mod Time
//Returns a multidimensional associative array
$handle = opendir($path);
if (!is_resource($handle)) return(FALSE);
while (false !== ($file = readdir($handle))) {
$fullPath = "$path/$file";
if (!(is_dir($fullPath) || is_link($fullPath))) {
$fileInfo = stat($fullPath);
if ($attrib != 13) {
$sortOrder[$fileInfo[1]] = $fileInfo[$attrib];
} else {
$sortOrder[$fileInfo[1]] = $file;
}
$directory[$fileInfo[1]]['name'] = $file;
$directory[$fileInfo[1]]['UID'] = $fileInfo[4];
$directory[$fileInfo[1]]['GID'] = $fileInfo[5];
$directory[$fileInfo[1]]['Size'] = $fileInfo[7];
$directory[$fileInfo[1]]['Mtime'] = $fileInfo[9];
}
}
if ($reverse) {
asort($sortOrder);
} else {
arsort($sortOrder);
}
$sortOrder = array_keys($sortOrder);
for ($i = 0; $i < sizeof($directory); $i++) {
$result[$i]['name'] = $directory[$sortOrder[$i]]['name'];
$result[$i]['UID'] = $directory[$sortOrder[$i]]['UID'];
$result[$i]['GID'] = $directory[$sortOrder[$i]]['GID'];
$result[$i]['Size'] = $directory[$sortOrder[$i]]['Size'];
$result[$i]['Mtime'] = $directory[$sortOrder[$i]]['Mtime'];
}
return($result);
}
?>