From d653d521aec812372e0fad982e6f4876475faada Mon Sep 17 00:00:00 2001 From: Igor Kalkov Date: Sat, 14 Jul 2018 00:32:24 +0200 Subject: [PATCH 1/2] Flag for hiding subdirs --- index.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index 8471e9b..a955ac0 100644 --- a/index.php +++ b/index.php @@ -14,9 +14,9 @@ $allow_delete = true; // Set to false to disable delete button and delete POST r $allow_upload = true; // Set to true to allow upload files $allow_create_folder = true; // Set to false to disable folder creation $allow_direct_link = true; // Set to false to only allow downloads and not direct link +$allow_show_folders = true; // Set to false to hide all subdirectories $disallowed_extensions = ['php']; // must be an array. Extensions disallowed to be uploaded - $hidden_extensions = ['php']; // must be an array of lowercase file extensions. Extensions hidden in directory index $PASSWORD = ''; // Set the password, to access the file manager... (optional) @@ -64,9 +64,9 @@ if($_GET['do'] == 'list') { $directory = $file; $result = []; $files = array_diff(scandir($directory), ['.','..']); - foreach($files as $entry) if($entry !== basename(__FILE__) && !in_array(strtolower(pathinfo($entry, PATHINFO_EXTENSION)), $hidden_extensions)) { - $i = $directory . '/' . $entry; - $stat = stat($i); + foreach ($files as $entry) if (!is_entry_ignored($entry)) { + $i = $directory . '/' . $entry; + $stat = stat($i); $result[] = [ 'mtime' => $stat['mtime'], 'size' => $stat['size'], @@ -119,6 +119,25 @@ if($_GET['do'] == 'list') { readfile($file); exit; } + +function is_entry_ignored($entry) { + if ($entry === basename(__FILE__)) { + return true; + } + + global $allow_show_folders; + if (is_dir($entry) && !$allow_show_folders) { + return true; + } + + $ext = strtolower(pathinfo($entry, PATHINFO_EXTENSION)); + if (in_array($ext, $hidden_extensions)) { + return true; + } + + return false; +} + function rmrf($dir) { if(is_dir($dir)) { $files = array_diff(scandir($dir), ['.','..']); From cf6d4b4fec4ccc296bb257638149a5b51fb32b3b Mon Sep 17 00:00:00 2001 From: Igor Kalkov Date: Sat, 14 Jul 2018 10:42:11 +0200 Subject: [PATCH 2/2] Use func params instead of global keyword --- index.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index a955ac0..a2069a3 100644 --- a/index.php +++ b/index.php @@ -64,7 +64,7 @@ if($_GET['do'] == 'list') { $directory = $file; $result = []; $files = array_diff(scandir($directory), ['.','..']); - foreach ($files as $entry) if (!is_entry_ignored($entry)) { + foreach ($files as $entry) if (!is_entry_ignored($entry, $allow_show_folders, $hidden_extensions)) { $i = $directory . '/' . $entry; $stat = stat($i); $result[] = [ @@ -120,12 +120,11 @@ if($_GET['do'] == 'list') { exit; } -function is_entry_ignored($entry) { +function is_entry_ignored($entry, $allow_show_folders, $hidden_extensions) { if ($entry === basename(__FILE__)) { return true; } - global $allow_show_folders; if (is_dir($entry) && !$allow_show_folders) { return true; }