zoukankan      html  css  js  c++  java
  • 【php】读取"文件列表"按时间倒序显示,并递归显示各层文件夹、!

    思路:

    1.读取该php所在文件夹的文件列表,用"改动时间、文件名称"做键值对,塞入数组。对"改动时间"倒序。(貌似不能直接按时间倒序读取文件列表,此处为间接方法)

    2.读取的若为文件直接输出,为文件夹就输出文件夹并递归扫描其下文件。


    <?

    php //遍历当前文件夹下全部文件的和文件夹,并以树装形式显示 //1.打开文件夹句柄。获取句柄资源 //2.读取句柄资源,并显示当前和子文件夹下的(文件夹和文件名) function getDirFile($path){ if(!($file_handler=opendir($path))) return; $fileNTimes=array(); //遍历-当前文件夹的"文件",排除该php文件 while(false !== ($file=readdir($file_handler))){ if($file=='.' || $file=='..' || $file=='index.php') continue; $fileNTimes[filemtime($path.'/'.$file)]=$file; } //倒序 krsort($fileNTimes); foreach ($fileNTimes as $mtime=>$file) { $file_path="$path/$file"; //路径 $rel_path=str_replace(__DIR__."/", "", $file_path); //相对路径 //若为-文件夹 if(is_dir($file_path)){ //依据"文件夹级别"缩进 if(substr_count($file_path,"/")>1){ $count=str_repeat("  ",substr_count($file_path,"/")); echo $count.'+'.$file; }else{ echo '+'.$file; } echo "<br/>"; getDirFile($file_path); } //若为-文件 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); ?

    >


    效果:




  • 相关阅读:
    Jfinal附件上传与重命名
    JFinal-BBS
    jFinal怎样连接sqlserver?
    关于jmeter响应结果用html查看乱码
    jmeter启动报错Error occurred during initialization of VM Could not reserve enough space for object heap errorlevel=1的解决方法
    Genymotion创建下载模拟器的时候出现Unable to create Genymotion virtual devices:Connection timeout错误
    Selenium IDE和Selenium RC的安装
    python+eclipse环境搭建
    第一个jemter测试脚本
    ulipad源码包配置环境及安装
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/6927223.html
Copyright © 2011-2022 走看看