diff --git a/view/listFiles.json.php b/view/listFiles.json.php index 1d08bd88a..4e6cd4b80 100644 --- a/view/listFiles.json.php +++ b/view/listFiles.json.php @@ -2,7 +2,11 @@ require_once dirname(__FILE__) . '/../videos/configuration.php'; require_once $global['systemRootPath'] . 'objects/Login.php'; header('Content-Type: application/json'); + +// Ensure extensions are in lowercase and unique +$global['allowed'] = array_map('strtolower', $global['allowed']); $global['allowed'] = array_unique($global['allowed']); + $files = array(); if(Login::canBulkEncode()){ if (!empty($_POST['path'])) { @@ -10,29 +14,26 @@ if (substr($path, -1) !== DIRECTORY_SEPARATOR) { $path .= DIRECTORY_SEPARATOR; } - //var_dump($path, file_exists($path)); + if (file_exists($path)) { - if (defined( 'GLOB_BRACE' )) { + if (defined('GLOB_BRACE')) { $extn = implode(",*.", $global['allowed']); $extnLower = strtolower($extn); $extnUpper = strtoupper($extn); $filesStr = "{*." . $extn . ",*" . $extnLower . ",*" . $extnUpper . "}"; - //var_dump($filesStr); - //echo $files; $video_array = glob($path . $filesStr, GLOB_BRACE); } else { - //var_dump($global['allowed']); $video_array = array(); foreach ($global['allowed'] as $value) { - $video_array += glob($path . "*." . $value); + $video_array = array_merge($video_array, glob($path . "*." . $value)); } } + $id = 0; foreach ($video_array as $key => $value) { $path_parts = pathinfo($value); $obj = new stdClass(); $obj->id = $id++; - //$obj->path_clean = ($value); $obj->path = _utf8_encode($value); $obj->name = _utf8_encode($path_parts['basename']); $files[] = $obj;