Browse Source

Add show filesize option

master
Skylar Ittner 3 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 = [
46 46
 ];
47 47
 // Actual path of the wwwroot
48 48
 $ROOTPATH = "/var/www/html";
49
+// Show file sizes
50
+$SHOWFILESIZE = true;
49 51
 
50 52
 // Fill in to add mirror download links to files
51 53
 $MIRRORBASE = [];
@@ -1193,9 +1195,18 @@ $EXT2MIME = [
1193 1195
 
1194 1196
 $path = explode('?', $_SERVER['REQUEST_URI'], 2)[0];
1195 1197
 $dir = realpath(__DIR__ . $path);
1198
+if ($dir == "") {
1199
+        $dir = __DIR__;
1200
+}
1196 1201
 if (strpos($dir, $ROOTPATH) !== 0) {
1197 1202
 	die("Access denied.");
1198 1203
 }
1204
+
1205
+function human_filesize($bytes, $decimals = 2) {
1206
+  $sz = 'BKMGTP';
1207
+  $factor = floor((strlen($bytes) - 1) / 3);
1208
+  return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
1209
+}
1199 1210
 ?>
1200 1211
 <!DOCTYPE html>
1201 1212
 <meta charset="utf-8">
@@ -1329,22 +1340,25 @@ word-break: break-all;
1329 1340
                                     echo "<span class=\"$icon fa-fw\"></span> ";
1330 1341
                                 }
1331 1342
                                 echo $f . "</a>\n";
1332
-                                if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) {
1333
-                                    echo "<span class=\"d-inline-flex justify-content-end "
1343
+                                echo "\t<span class=\"d-inline-flex justify-content-end "
1334 1344
                                     . "align-items-center flex-wrap ml-auto\">\n";
1335
-                                    echo "\t<a href=\"$path$f\" class=\"my-1 btn btn-outline-default btn-sm\">"
1345
+                                if ($SHOWFILESIZE&& !is_dir($dir . "/" . $f)) {
1346
+                                    echo "\t\t<span class=\"filesize badge\">" . human_filesize(filesize($dir . "/" . $f)) . "</span>\n";
1347
+                                }
1348
+                                if (count($MIRRORBASE) > 0 && !is_dir($dir . "/" . $f)) {
1349
+                                    echo "\t\t<a href=\"$path$f\" class=\"my-1 btn btn-outline-default btn-sm\">"
1336 1350
                                     . "<span class=\"fas fa-cloud-download-alt\"></span>"
1337 1351
                                     . " Main</a>\n";
1338 1352
                                     foreach ($MIRRORBASE as $mirror) {
1339 1353
                                         $name = $mirror["name"];
1340 1354
                                         $base = $mirror["base"];
1341
-                                        echo "\t<a href=\"$base$path$f\""
1355
+                                        echo "\t\t<a href=\"$base$path$f\""
1342 1356
                                         . " class=\"ml-2 my-1 btn btn-outline-default btn-sm\">"
1343 1357
                                         . "<span class=\"fas fa-cloud-download-alt\"></span>"
1344 1358
                                         . " $name</a>\n";
1345 1359
                                     }
1346
-                                    echo "</span>";
1347 1360
                                 }
1361
+                                echo "\t</span>\n";
1348 1362
                                 echo "</li>\n\n";
1349 1363
                             }
1350 1364
                         }

Loading…
Cancel
Save