- glob: documentation ( source)
- str_replace: documentation ( source)
- preg_replace: documentation ( source)
- header: documentation ( source)
- is_dir: documentation ( source)
<?php
function treeList($path = "") {
$prefix = ($path == "") ? $_SERVER['DOCUMENT_ROOT'] : "";
$return = preg_replace("#(.*)/(.*)$#u","\$1",$path);
echo ' <ul> ';
echo ' <li><a href="?path='.$return.'">[...назад...]</a></li> ';
foreach (glob($_SERVER['DOCUMENT_ROOT']."$path/*") as $item) {
$isdir = (is_dir($item)) ? true : false;
$item = str_replace(array($_SERVER['DOCUMENT_ROOT'],"//"),array("","/"),$item);
if ($isdir) echo ' <li><b><a href="?path='.$item.'">'.$item.'</a></b></li> ';
else echo ' <li>'.$item.'</li> ';
}
echo ' </ul> ';
}
$path = (isset($_GET['path'])) ? $_GET['path'] : "";
header("Content-Type: text/html; charset=utf-8");
treeList($path);