Browse Source

Add show filesize option

master
Skylar Ittner 5 months ago
parent
commit
8271a0c3db
1 changed files with 19 additions and 5 deletions
  1. 19
    5
      index.php

+ 19
- 5
index.php View File

@@ -46,6 +46,8 @@ $IGNORE = [
];
// Actual path of the wwwroot
$ROOTPATH = "/var/www/html";
// Show file sizes
$SHOWFILESIZE = true;

// Fill in to add mirror download links to files
$MIRRORBASE = [];
@@ -1193,9 +1195,18 @@ $EXT2MIME = [

$path = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
$dir = realpath(__DIR__ . $path);
if ($dir == "") {
$dir = __DIR__;
}
if (strpos($dir, $ROOTPATH) !== 0) {
die("Access denied.");
}

function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
?>
<!DOCTYPE html>
<meta charset="utf-8">
@@ -1329,22 +1340,25 @@ word-break: break-all;
echo "<span class=\"$icon fa-fw\"></span> ";
}
echo $f . "</a>\n";
if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) {
echo "<span class=\"d-inline-flex justify-content-end "
echo "\t<span class=\"d-inline-flex justify-content-end "
. "align-items-center flex-wrap ml-auto\">\n";
echo "\t<a href=\"$path$f\" class=\"my-1 btn btn-outline-default btn-sm\">"
if ($SHOWFILESIZE&& !is_dir($dir . "/" . $f)) {
echo "\t\t<span class=\"filesize badge\">" . human_filesize(filesize($dir . "/" . $f)) . "</span>\n";
}
if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) {
echo "\t\t<a href=\"$path$f\" class=\"my-1 btn btn-outline-default btn-sm\">"
. "<span class=\"fas fa-cloud-download-alt\"></span>"
. " Main</a>\n";
foreach ($MIRRORBASE as $mirror) {
$name = $mirror["name"];
$base = $mirror["base"];
echo "\t<a href=\"$base$path$f\""
echo "\t\t<a href=\"$base$path$f\""
. " class=\"ml-2 my-1 btn btn-outline-default btn-sm\">"
. "<span class=\"fas fa-cloud-download-alt\"></span>"
. " $name</a>\n";
}
echo "</span>";
}
echo "\t</span>\n";
echo "</li>\n\n";
}
}

Loading…
Cancel
Save