From 8271a0c3db1c2470d879250495725f78411615e5 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 3 Apr 2019 01:56:33 -0600 Subject: [PATCH] Add show filesize option --- index.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 550c42a..9867cb9 100644 --- a/index.php +++ b/index.php @@ -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]; +} ?> @@ -1329,22 +1340,25 @@ word-break: break-all; echo " "; } echo $f . "\n"; - if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) { - echo "\n"; - echo "\t" + if ($SHOWFILESIZE&& !is_dir($dir . "/" . $f)) { + echo "\t\t" . human_filesize(filesize($dir . "/" . $f)) . "\n"; + } + if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) { + echo "\t\t" . "" . " Main\n"; foreach ($MIRRORBASE as $mirror) { $name = $mirror["name"]; $base = $mirror["base"]; - echo "\t" . "" . " $name\n"; } - echo ""; } + echo "\t\n"; echo "\n\n"; } }