".h($title)."");
}
function print_header() {
global $link_prefix, $link_base, $to_dir;
$path_tree = "/";
if ($link_prefix == '/') {
$path_tree = link_to('/', '[root]').'/';
}
foreach ($to_dir as $level => $dir) {
if($dir) {
$link = "/";
for ($i = 0; $i <= $level; $i++) { $link .= "$to_dir[$i]/"; }
$path_tree .= link_to($link, $dir)."/";
}
}
header('Content-Type: text/html; charset=utf-8');
echo "
Index of ", h(rtrim($link_base,"/")."/"), "
Index of $path_tree
";
}
function nice_size($size) {
static $unit = array('B', 'KB', 'MB', 'GB', 'TB');
for ($i = 0; $size >= 1000 && $i < count($unit); $i++) { $size /= 1000; }
if ($i == 0) { return(sprintf("%d %s", $size, $unit[$i])); }
else { return(sprintf("%.2f %s", $size, $unit[$i])); }
}
function file_rows($files, $is_dir) {
global $path, $link_base, $link_prefix;
$file_rows = "";
if ($is_dir) {
$file_suffix = "/";
if($link_base != $link_prefix) {
$file_rows .= "".link_to(dirname($link_base),"..")." |
";
}
} else { $file_suffix = ""; }
foreach($files as $file) {
$file_stat = stat("$path/".$file);
$file_rows .= "".
link_to("$link_base/".$file, $file.$file_suffix)." | ".
h(strftime("%a %d-%b-%G %H:%M", $file_stat['mtime']))." | ";
if ($is_dir) { $file_rows .= "[dir]"; }
else { $file_rows .= nice_size($file_stat['size']); }
$file_rows .= " |
";
}
return $file_rows;
}
function print_list() {
global $dirs, $files;
echo "",
"File | ",
"Date | ",
"Size | ",
"
",
"", file_rows($dirs, true), file_rows($files, false), "",
"
";
}
function print_footer() {
echo "";
}
print_header();
print_list();
print_footer();
?>