
22/11/2010, 12:34
|
| | Fecha de Ingreso: diciembre-2009 Ubicación: Sevilla
Mensajes: 49
Antigüedad: 15 años, 2 meses Puntos: 0 | |
Listar archivos ordenados por fecha Muy buenas a todos.
Me gustaría saber si alguién me puede ayudar con este código. Por que no tengo maneras de ordenar este listado de archivos mediante la fecha (que me muestre el más reciente al principio y el más antiguio al final).
Aquí os dejo el código que tengo hecho. <?php
// read all php file in the current directory
if ($dh = opendir('./')) {
$files = array();
while (($file = readdir($dh)) !== false) {
if (substr($file, strlen($file) - 4) == '.doc') {
array_push($files, $file);
}
}
closedir($dh);
}
// Sort the files and display
sort($files);
echo "<ul>\n";
foreach ($files as $file) {
$title = Title($file);
echo "<li><a href=\"$file\" title=\"$title\">$title</a></li>\n";
}
echo "</ul>\n";
// Function to get a human readable title from the filename
function Title($filename) {
$title = substr($filename, 0, strlen($filename) - 4);
$title = str_replace('-', ' ', $title);
$title = ucwords($title);
return $title;
}
?> |