php按日期倒序查询,【php】讀取"文件列表"按時間倒序顯示,並遞歸顯示各層文件夾、!...

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 "
";

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 "
";

}

}

}

function getTime_html($time){

return ' '.date('(Y-m-d H:m:s)',$time).'';

}

function getFile_html($rel_path,$file){

return ''.$file.'';

}

//-----------------------------------------

$path=__DIR__;

getDirFile($path);

?

>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值