Bonsoir,
J'ai un code php qui me classe par date mes fichiers, le problème c'est qu'il m'affiche toute arborescence donc j'aimerais un moyen d"affiché que les 10 dernier fichier ajouté.
Voici le code
Si quelqu'un a une idée je suis preneur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 <?php // repertoire a scanner : $dir= "dossier"; // comparateur de date function dateComparator($a, $b) { if ($a['date_modification'] == $b['date_modification']) return 0; return ($b['date_modification'] < $a['date_modification']) ? -1 : 1; } // scan du repertoire $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); $fichiers=array(); foreach ($iterator as $path) { // si il s'agit d'un fichier if ($path->isFile()) // on cree une matrice d'informations sur le fichier $fichiers[]= array( "nom" => pathinfo($path->__toString(), PATHINFO_BASENAME), "date_modification" => filemtime($path) ); } // tri par date usort($fichiers, 'dateComparator'); // affichage du tableau de fichiers apres tri par date echo "<h3>Derniers fichiers téléchargés : </h3>"; echo "<hr/>"; foreach($fichiers as $key => $item) { echo "[".$key."] ".date("d/m/Y H:i:s", $item['date_modification'])." | ".$item['nom']."<br/>"; } echo "<hr/>"; ?>
Partager