File size: 2.64Kb
<?php
header("Content-Type: text/html; charset=utf-8");
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Листинг директорий
</title>
<style type="text/css">
body {
background-color:yellow; color: blue; padding:2px; }
.text {
background-color: white; color:black; margin:2px; padding:3px; border 1px solid silver;}
.dir {
padding: 3px;
border-top: 1px solid silver; }
.file {
padding: 3px;
border-top: 1px solid silver; }
.p {
background-color: orange; color:aqua; padding:3px; margin: 1px; border-top: 1px solid white; }
.p a {
color: white; }
.text a {
color: blue; }
.dir a {
color:red; }
.file a {
color:blue; }
a {
color: red; }
</style>
</head>
<body>';
$end=base64_decode(nav_page());
if (empty($_GET['fol_id']))
{
$fol_id=$_SERVER['DOCUMENT_ROOT'].''.dirname($_SERVER['PHP_SELF']);
}
else
{
$fol_id=$_GET['fol_id'];
}
function read_dir($dir)
{
$size='0';
if ($path = opendir($dir))
while ($file_name = readdir($path))
{
if (($file_name!=='.') && ($file_name!==".."))
{
if ( is_dir($dir."/".$file_name))
{
$size +=read_dir($dir."/".$file_name);
}
else
{
$size += filesize($dir."/".$file_name);
}
}
}
closedir ($path);
return $size;
}
function formatsize($file_size)
{
if($file_size >= 1073741824)
{
$file_size=round($file_size / 1073741824 * 100) / 100 . " Gb";
}
elseif(
$file_size >= 1048576)
{
$file_size=round($file_size / 1048576 * 100) / 100 . " Mb";
}
elseif(
$file_size >= 1024)
{
$file_size=round($file_size / 1024 * 100) / 100 . " Kb";
}
else
{
$file_size=round($file_size) . " b";
}
return $file_size;
}
function nav_page()
{
return 'PGEgaHJlZj0iaHR0cDovL3N2b2JvZGEudjFwLnN1Ij5ieSBQcm90b248L2E+PGJyLz48L2JvZHk+PC9odG1sPg==';
}
echo '<div class="text">';
$dirname=str_replace($_SERVER['DOCUMENT_ROOT'],'',$fol_id.'/');
echo 'Каталог: '.$dirname.' ('.formatsize(read_dir($fol_id)).')<br/>';
$glob=glob("$fol_id/*");
for ($i=0;$i<count($glob);$i++)
{
$glob[$i]=str_replace('////','/',$glob[$i]);
$glob[$i]=str_replace('///','/',$glob[$i]);
$glob[$i]=str_replace('//','/',$glob[$i]);
$filename=str_replace($_SERVER['DOCUMENT_ROOT'],'',$glob[$i]);
if (is_dir($glob[$i]))
{
echo '<div class="dir">
<b>'.($i+1).'.</b> <a href="?fol_id='.$glob[$i].'">'.$filename.'</a> ('.formatsize(read_dir($glob[$i])).')<br/></div>';
}
else
{
echo '<div class="file">
<b>'.($i+1).'.</b> <a href="'.$filename.'">'.$filename.'</a> ('.formatsize(filesize($glob[$i])).')<br/></div>';
}
}
echo '</div>
<div class="p">
<form action="" method="get">
Текущий адрес:<br/>
<textarea name="fol_id" nums="25" rows="3">'.$fol_id.'</textarea><br/>
<input type="submit" value="Перейти"/>
</form></div>';
echo $end;
?>