Ideas:
1. Read the list of files in the directory where PHP is located, and use "Modify time, file name" as the key-value pair and plug in the array. Reverse the "Modified time". (seemingly unable to read the file list directly in reverse chronological order, here is the indirect method)
2. If the read is the direct output of the file, the directory is the output directory and recursively scan its next file.
<?php//iterates through all the files and directories in the current directory, and displays//1 as a tree. Open the directory handle to get the handle resource//2. Reads the handle resource and displays the (directory and file name) function Getdirfile ($path) {if (! ($file _handler=opendir ($path))) return; $fileNTimes =array ();//traverse-The current directory "file", excluding the PHP file while (False!== ($file =readdir ($file _handler)) {if ($file = = '. ' | | $file = = ' ... ' | | $file = = ' index.php ') continue; $fileNTimes [Filemtime ($path. ') /'. $file)]= $file;} Reverse Krsort ($fileNTimes), foreach ($fileNTimes as $mtime = = $file) {$file _path= "$path/$file";//Path $REL_PATH=STR_ Replace (__dir__. " /"," ", $file _path);//relative path//If-directory if (Is_dir ($file _path)) {//According to" directory Level "indent if (Substr_count ($file _path,"/") >1) {$count =str_repeat (" ", Substr_count ($file _path, "/")); Echo $count. ' + '. $file;} Else{echo ' + '. $file;} echo "<br/>"; Getdirfile ($file _path);} If-File Else{if (Substr_count ($file _path, "/") >1) {$count =str_repeat (" ", Substr_count ($file _path, "/" ); Echo $count. getfile_html ($rel _path, $file). gettime_html ($mtime);} Else{echo getfile_html ($file, $file). gettime_html ($mtime);} echo "<br/>";}}} function getTime_html ($time) {return ' <a style= ' Font-size:10px;color:grey ' > '. Date (' (y-m-d h:m:s) ', $time). ' </a> ';} function getfile_html ($rel _path, $file) {return ' <a href= '. $rel _path. ' " > '. $file. ' </a> ';} -----------------------------------------$path =__dir__;getdirfile ($path);? >
Effect: