"PHP" read "file list" in reverse chronological display, and recursively display each level of directory,!

Source: Internet
Author: User

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:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.