PHP 文件夹 生成 html目录树

to_top_com to_top_com 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<?php
/*作者:梦行Monxin*/
header('Content-Type:text/html;charset=utf-8');
$path='./';
$v=get_dir_to_html($path);
file_put_contents('dir.html',$v);
echo $v;

function get_dir_to_html($path){
$r=scandir($path);
$html='';
$dirs='';
$files='';
$t='';
foreach($r as $v){
if($v=='.' || $v=='..'){continue;}

$v=iconv('gbk',"UTF-8".'//IGNORE',$v);
if(is_dir($path.$v)){
$t.="\t";
$dirs.=$t.'<li class=dir id="'.trim($path.$v,'./').'"><div class=line><div>'.$v."</div><div></div></div>\r\n".$t.get_dir_to_html($path.$v.'/')."</li>\r\n";
}else{
$temp=explode('.',$v);
$files.=$t.'<li class='.$temp[count($temp)-1].' id="'.trim($path.$v,'./').'"><div class=line><div>'.$v."</div><div></div></div></li>\r\n";;
}
}
if($dirs!='' || $files!=''){$html="<ul>".$dirs.$files."</ul>\r\n";}
return $html;
}

//最后再后百度"html 格式化",让它有TAB符,看起来更清晰
?>
...全文
评论 1
收藏 已收藏
分享
返回顶部
to_top_com
基础编程 21,889 成员 140,329 内容