function getFiles($path,$lvl = 0){
$res = [];
$dir2 = scandir($path);
foreach($dir2 as $file2){
if (($file2!='.') && ($file2!='..')){
$fullpath = $path . DIRECTORY_SEPARATOR . $file2;
if(is_dir($fullpath)){
$res = array_merge($res,getFiles($fullpath,$lvl+1));
array_push($res,["path"=>$fullpath,"name"=>$file2,"type"=>"DIR","level"=>$lvl,"size"=>filesize($fullpath)]);
}else if(is_file($fullpath))
array_push($res,[ "path"=>$fullpath,"name"=>$file2,"type"=>"FILE","level"=>$lvl,"size"=>filesize($fullpath)]);
}
}
return $lvl == 0 ? array_reverse($res): $res;
}
function showFiles($arr){
foreach($arr as $v){
$margin = $v["level"] * 15;
if($v["type"] == "DIR")
echo "<span style='display:block;font-weight:bold;margin-left:{$margin}px;'>$v[name]</span>";
if($v["type"] == "FILE")
echo "<a style='margin-left:{$margin}px;display:block;' href='$v[path]'>$v[name] ($v[size] байт)</a>";
}
}
showFiles(getFiles('yourdir'));