<html>
<head>
<title>miblounge.net - FH</title>
<style type="text/css">
a:link { font-weight:bold; color:blue; text-decoration:none; }
a:visited { font-weight:bold; color:blue; text-decoration:none; }
a:focus { font-weight:bold; color:red; text-decoration:underline; }
a:hover { font-weight:bold; color:red; text-decoration:none; }
a:active { font-weight:bold; color:red; text-decoration:underline; }
table.filelist { font-family: Courier; font-size:9pt; }
th.filelist { font-family: Arial,Helvetica; font-size:9pt; }
body { font-family: Arial, Helvetica; }
</style>
</head>
<body>
<?php
// $filename kann ein String oder ein Array sein...
function RenameIfRequired($rootpath, $filename)
{
$newfilename = $filename;
$newfilename = str_replace(array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'), array('ae', 'oe', 'ue', 'AE', 'OE', 'UE', 'ss'), $newfilename);
// Diese Zeile hier nun ist die wichtige :-)
$newfilename = str_replace(array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'), array('ae', 'oe', 'ue', 'AE', 'OE', 'UE'), $newfilename);
if (is_array($filename)) {
for ($i = 0; $i < count($filename); $i++) {
if ($filename[$i] != $newfilename[$i]) {
rename($rootpath.$filename[$i], $rootpath.$newfilename[$i]);
}
}
} else {
if ($newfilename != $filename) {
rename($rootpath.$filename, $rootpath.$newfilename);
}
}
return $newfilename;
}
function getDisplayName($dir)
{
$dirs = split("/", $dir);
$whole = "";
$cdir = "";
foreach ($dirs as $d) {
if ($d == "") continue;
$cdir .= $d."/";
$cdirinfoname = $cdir.'dirinfo.hidden.txt';
// echo "Getting '$cdirinfoname'<br>";
if (file_exists($cdirinfoname)) {
$whole .= implode ('', file ($cdirinfoname))."/";
} else {
if ($d == ".") continue;
$whole .= $d."/";
}
}
if ($whole[0] == "/") $whole = substr($whole, 1);
if ($whole[strlen($whole)-1] == "/") $whole = substr($whole, 0, strlen($whole)-1);
return $whole;
}
function getFileList($dir)
{
# array to hold return value
$retval = array();
# add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";
# open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
$entries[] = $entry;
}
$d->close();
if (!isset($entries)) return null;
sort($entries);
foreach ($entries as $entry) {
# skip hidden files
if($entry[0] == ".") continue;
if(strpos($entry, ".php") > 0) continue;
if(strpos($entry, ".hidden") > 0) continue;
if(is_dir("$dir$entry")) continue;
if(!is_readable("$dir$entry")) continue;
$newfilename = RenameIfRequired($dir, $entry);
$retval[$newfilename] = array(
"name" => "$newfilename",
"type" => "", // mime_content_type("$dir$newfilename"),
"size" => filesize("$dir$newfilename"),
"lastmod" => filemtime("$dir$newfilename")
);
}
return $retval;
}
function getDirectoryList($dir)
{
# array to hold return value
$retval = array();
# add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";
# open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
$entries[] = $entry;
}
$d->close();
if (!isset($entries)) return null;
sort($entries);
foreach ($entries as $entry) {
# skip hidden files
if($entry[0] == ".") continue;
if(!is_dir("$dir$entry")) continue;
if(strpos($entry, ".php") > 0) continue;
if (file_exists($dir.$entry."/dirinfo.hidden.txt")) {
$displayname = implode ('', file ($dir.$entry."/dirinfo.hidden.txt"));
} else {
$displayname = $entry;
}
$retval[] = array(
"name" => "$entry/",
"displayname" => "$displayname",
"type" => "Verzeichnis",
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
}
return $retval;
}
function sizestr($size)
{
$l = strlen($size);
$c = 3;
while ($c < $l) {
$size = substr($size, 0, $l-$c).".".substr($size, $l-$c);
$c = $c + 4;
$l++;
}
return $size;
}
function formattime($t)
{
return date("d.m.y H:i:s", $t);
}
$rootdir = "./";
$rootdisplaydir = "FH";
$subdir = "";
if (isset($_GET["dir"])) {
$subdir = $_GET["dir"];
}
if (strpos($subdir, "..") !== false) {
exit;
}
$absdir = $rootdir.$subdir;
$filelist = getFileList($absdir);
$dirlist = getDirectoryList($absdir);
echo "<h1>".getDisplayName($rootdir.$subdir)."</h1>";
echo "<table class=\"filelist\" border=\"0\" cellspacing=\"2\">\n";
echo "<colgroup>\n";
echo " <col width=\"400\">";
echo " <col width=\"120\" align=\"right\">";
echo " <col width=\"180\" align=\"center\">";
echo " </colgroup>";
echo "<tr><th class=\"filelist\">Name</th><th class=\"filelist\" align=\"center\">Größe</th><th class=\"filelist\">geändert am</th></tr>\n";
if ($subdir != "") {
$parentdir = substr($subdir, 0, strlen($subdir)-1);
$p = strrpos($parentdir, "/");
if ($p === false) {
$parentdir = "";
} else {
$parentdir = substr($parentdir, 0, $p + 1);
}
echo "<tr>\n";
echo "<td><a href=\"index.php?dir=".urlencode($parentdir)."\">..</a></td>\n";
echo "<td> </td>\n";
echo "<td> </td>\n";
echo "</tr>\n";
}
foreach($dirlist as $file) {
echo "<tr>\n";
echo "<td><a href=\"index.php?dir=".urlencode($subdir.$file['name'])."\">{$file['displayname']}</a></td>\n";
echo "<td> </td>\n";
echo "<td style=\"text-align:center\">" . formattime($file['lastmod']) . "</td>\n";
echo "</tr>\n";
}
$csize = 0;
$lastone = -1;
foreach($filelist as $fn=>$file) {
echo "<tr>\n";
echo "<td><a href=\"".$subdir.$file['name']."\">{$file['name']}</a></td>\n";
echo "<td style=\"text-align:right\">" . sizestr($file['size']) . "</td>\n";
echo "<td style=\"text-align:center\">" . formattime($file['lastmod']) . "</td>\n";
echo "</tr>\n";
$csize += $file['size'];
if ($file['lastmod'] > $lastone) $lastone = $file['lastmod'];
}
/*if ($filelist != null) {
echo "<tr>\n";
echo "<td>Dateien gezippt runterladen</td>\n";
echo "<td><= " . sizestr($csize) . "</td>\n";
echo "<td>" . formattime($lastone) . "</td>\n";
echo "</tr>\n";
}*/
echo "</table>\n\n";
?>
</body>
</html>