Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/11/2010, 16:48
Josamulai
 
Fecha de Ingreso: diciembre-2009
Ubicación: Sevilla
Mensajes: 49
Antigüedad: 14 años, 4 meses
Puntos: 0
Ordenar acrhivos por fecha con php

Muy buenas a todos,

Resulta que estoy intentando listar archivos de un directorio para que se muestre en mi web. Sin embargo o consigo ordenarlos por fecha, si hay algiuen que pueda echarme un cable lo agradecería.

Os dejo el código que tengo hasta ahora para ver como se puede modificar para mostrar mis archivos ordenados por fecha:



<?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) == '.pdf') {
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;
}
?>

Muchas gracias de antemano.

Saludos

Josamulai