script problem ang filer og mapper...
jeg har følgende script :<?
function kbIze($n)
{
if ($n == 0) return 0;
$tmp = $n/1024;
$type = \"kb\";
if ($tmp < 1)
{
$tmp = $n;
$type = \"b\";
}
return number_format($tmp,0,\",\",\".\") . \" $type\";
}
$title = \"Directory Index\";
$header = \"
<html>
<head>
<title>{title}</title>
<style type=\\\"text/css\\\">
body {
font-size: 18px;
color: blue;
background-color: white;
}
h1 { }
a { color: blue; }
a:hover { text-decoration: none; }
</style>
</head>
<body>\\n\";
if ($showsource) { ob_end_clean(); show_source(\"index.php\"); exit; }
if (strlen($QUERY_STRING) == 0)
{
header(\"location: ?/\");
exit;
}
// Only show files/dirs that are at the same level or deeper than this file!
$SAFE_DIR = realpath(dirname(\"./\".basename($PHP_SELF)));
$what = urldecode($QUERY_STRING);
if ($what[0] == \"/\") $what = substr($what,1);
$item = realpath($SAFE_DIR.\"/\".$what);
if (strlen($item) == 0)
echo preg_replace(\"/{title}/\",$title,$header) . \"The file $what does not exist!\";
elseif (!preg_match(\"/^\". str_replace(\"/\",\"\\/\",$SAFE_DIR) . \"/\",$item))
echo preg_replace(\"/{title}/\",$title,$header) . \"Fetching that file is not allowed!\";
elseif (is_file($item))
{
header(\"location: $what\");
exit;
}
else
{
$what = substr($item,strlen($SAFE_DIR));
$dh = opendir($item);
$what = (strlen($what) > 0 ? $what : \"/\");
$title = \"Index of $what\";
echo preg_replace(\"/{title}/\",$title,$header) . \"<h1>$what</h1>\\n\";
$parent = substr(realpath($item.\"/..\"),strlen($SAFE_DIR));
echo \"<table border=\'0\' cellspacing=\'0\' cellpadding=\'0\'>\\n\";
if (strlen($what) > 1) echo \"<tr><td valign=\'top\' colspan=\'2\'><a href=\'?$parent\'><- parent directory<br><br></td></tr>\\n\";
echo \"<tr><td valign=\'top\'><b><i>Name</i></b></td><td valign=\'top\' align=\'right\'><b><i>Size</i></b></td></tr>\";
while ($file = readdir($dh))
{
if ($file != \".\" && $file != \"..\" && !($what == \"/\" && $file == \"index.php\") && !preg_match(\"/^\\./\",$file)&& $file != \"12c\")
if ($file != \".\" && $file != \"..\" && !($what == \"/\" && $file == \"freepaqdefault.html\") && !preg_match(\"/^\\./\",$file)&& $file != \"12c\")
{
echo \"<tr><td valign=\'top\'><a href=\'download.php?\" . (strlen($what) > 1 ? \"$what\" : \"\") .\"$file\'>$file</a>\";
echo \"<td valign=\'top\' align=\'right\'> \";
if (is_dir($item.\"/\".$file))
echo \"<DIR>\";
else
echo kbIze(filesize($item.\"/\".$file));
echo \"</td></tr>\\n\";
}
}
echo \"</table>\\n\";
}
?>
<?
$taeller = join(\"\",file(\".count.txt\"));
$fp = fopen(\".count.txt\",\"w\");
flock($fp,LOCK_EX);
fwrite($fp,++$taeller);
fclose($fp);
?>
Det echoer alt + laver links til hvad der ligger i en mappe (filer og undermapper)
hvis det er en fil skal den videreføre til filen download.php med stringen, hvilket den også gør fint..
men problemet er når det er en mappe, gør den det samme, hvor den jo selvfølgelig istedet skal gå ind i den...
Hvordan retter man dette?
Mvh
mental
