reorchestrating

This commit is contained in:
Ville Rantanen
2016-03-08 13:23:31 +02:00
parent 17f6505ab9
commit 4b06eaeff9
19 changed files with 181 additions and 220 deletions

90
web/index.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
$cellcolor = "#BCD2EE";
$hovercolor = "#BCD2EE";
$dirr="./"; // Directory to read for files
$pre="./"; // prefix for download urls
$title="Index of files";
$header= '
<html><head><title>'.$title.'</title>
<style>
body {font-family:Monospace;}
A:link { text-decoration:none; color:blue; }
A:visited { text-decoration:none; color:gray ;}
tr:hover td
{
background-color:white;
}
TABLE {
width: 60%;
}
TD {
background-color: '.$cellcolor.';
white-space:nowrap;
}
.date { width: 20%; }
.size { width: 10%; text-align: right; }
</style>
</head>
<body>
';
//////////////////////////////////////////// script starts /////////////////
function normal($header, $content, $linkcontent,$pre,$preurl) {
echo $header;
$sum=0;
echo "<h1>".basename(dirname($_SERVER['PHP_SELF']))."</h1>";
echo '<table>';
echo "<tr><th>File<th>Size<th>Modified\r\n";
if (is_file("../index.php") || is_file("../index.html")) {
echo "<tr><td class=\"name\"><a href=\"..\">..</a><td class=\"size\">[DIR]<td class=\"date\">\r\n";
}
foreach ($content as $k => $v) {
if (is_dir($pre.$v)) {
$name = htmlentities(rtrim($v));
$linkname = $preurl.rtrim($linkcontent[$k]);
$date=date("Y-m-d H:i",filemtime($pre.$name));
echo "<tr><td class=\"name\"><a href=\"$linkname\">$name</a><td class=\"size\">[DIR]<td class=\"date\">$date\r\n";
}
}
foreach ($content as $k => $v) {
if (is_file($pre.$v)) {
$name = htmlentities(rtrim($v));
$linkname = $preurl.rtrim($linkcontent[$k]);
$size = filesize($pre.$name);
$sum = $sum + $size;
$j = 0; $ext = array("B","kB","MB","GB","TB","PB");
while ($size >= pow(1024,$j)) ++$j;
$size = round($size / pow(1024,$j-1) * 100) / 100 . " ".$ext[$j-1];
$date=date("Y-m-d H:i",filemtime($pre.$name));
echo "<tr><td class=\"name\"><a href=\"$linkname\">$name</a><td class=\"size\"> $size<td class=\"date\"> $date\r\n";
}
}
echo "\r</table>";
echo "</body></html>";
// end of "normal" function
}
/// Let's put the files in $content...
$d = dir($dirr);
$i=0;
while ($filename = $d->read()) {
if ($filename == "index.php") { continue; }
if (substr($filename,0,1) == ".") { continue; }
$content[$i] = $filename;
$linkcontent[$i] = rawurlencode($content[$i]);
$i++;
}
$d->close();
// Rid of unwanted files....
array_multisort($content,$linkcontent);
normal($header,$content, $linkcontent,$dirr,$pre);
?>