$d, "files" => $result['files'], "directories" => $result['directories'] ); } else { if ($filter == null OR ($filter != null AND $filter("$root/$dir/$d"))) // IF no filter, or filter matches, add file. { $files[$d] = array("path" => $dir, "name" => $d, "size" => filesize("$root/$dir/$d"), "date" => filemtime("$root/$dir/$d")); if ( time() - $files[$d]['date'] < RECENT_MAX) { $recent[] = $files[$d]; // Add to recent list. } } } } return array("files" => $files, "directories" => $dirs); } function custom_sort($key, $direction) // Sort on $key, in the specified direction (-1 = descending, 1 = ascending) { return function($a, $b) use ($key, $direction) { if ($a[$key] == $b[$key]) { return 0; } if ($key == 'date' OR $key == 'size') { return ($a[$key] < $b[$key]) ? $direction : -$direction; } else { return ($direction) * strnatcasecmp($a[$key], $b[$key]); } }; } // usort($files, custom_sort($sort)); function output_map($map, $sort, $direction) // Output the file/directory map. Sort files by $sort, $direction { // Sort directories. if (count($map['directories']) > 0) { usort($map['directories'], custom_sort('name', 1)); } // Sort files. if (count($map['files']) > 0) { usort($map['files'], custom_sort($sort, $direction)); } // Output each dir. echo '
    '; foreach ($map['directories'] as $d ) { echo '
  • Folder icon' . $d['name']; output_map ($d, $sort, $direction); echo '
  • '; } echo "
"; echo '