Skip to content

Commit 7e9eb3e

Browse files
author
Daniel Neto
committed
Update
1 parent d03de20 commit 7e9eb3e

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

view/listFiles.json.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,50 @@
88
ini_set('log_errors', 1);
99

1010
if (empty($global['allowed'])) {
11-
$global['allowed'] = array();
11+
$global['allowed'] = [];
1212
}
1313

14-
// Ensure extensions are in lowercase and unique
1514
$global['allowed'] = array_map('strtolower', $global['allowed']);
1615
$global['allowed'] = array_unique($global['allowed']);
1716

18-
$files = array();
17+
$files = [];
1918

2019
if (Login::canBulkEncode()) {
2120
if (!empty($_POST['path'])) {
22-
$path = rtrim($_POST['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
23-
24-
// Log the received path
25-
error_log("Bulk Encode: Received path - " . $path);
26-
27-
if (!file_exists($path)) {
28-
error_log("Bulk Encode Error: Path does not exist - " . $path);
29-
echo json_encode(["error" => "Path does not exist"]);
21+
$path = realpath($_POST['path']);
22+
if ($path === false) {
23+
error_log("Bulk Encode Error: realpath() failed for " . $_POST['path']);
24+
echo json_encode(["error" => "Invalid path"]);
3025
exit;
3126
}
27+
$path .= DIRECTORY_SEPARATOR;
28+
error_log("Bulk Encode: Resolved path - " . $path);
3229

33-
if (!is_readable($path)) {
34-
error_log("Bulk Encode Error: Path is not readable - " . $path);
35-
echo json_encode(["error" => "Path is not readable"]);
30+
if (!file_exists($path) || !is_readable($path)) {
31+
error_log("Bulk Encode Error: Path not accessible - " . $path);
32+
echo json_encode(["error" => "Path not accessible"]);
3633
exit;
3734
}
3835

39-
$video_array = array();
40-
foreach ($global['allowed'] as $ext) {
41-
$filesFound = glob($path . "*." . $ext);
42-
if ($filesFound === false) {
43-
error_log("Bulk Encode Error: glob() failed for extension .$ext in path $path");
44-
} else {
45-
error_log("Bulk Encode: Found " . count($filesFound) . " files with extension .$ext");
36+
$video_array = [];
37+
$dirContents = scandir($path);
38+
39+
if ($dirContents !== false) {
40+
foreach ($dirContents as $file) {
41+
$filePath = $path . $file;
42+
if (is_file($filePath)) {
43+
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
44+
if (in_array($ext, $global['allowed'])) {
45+
$video_array[] = $filePath;
46+
}
47+
}
4648
}
47-
$video_array = array_merge($video_array, $filesFound);
49+
} else {
50+
error_log("Bulk Encode Error: scandir() failed for " . $path);
4851
}
4952

5053
if (empty($video_array)) {
51-
error_log("Bulk Encode Warning: No files found in the directory.");
54+
error_log("Bulk Encode Warning: No files found.");
5255
}
5356

5457
$addedFiles = [];
@@ -57,7 +60,6 @@
5760
if (isset($addedFiles[strtolower($value)])) {
5861
continue;
5962
}
60-
6163
$addedFiles[strtolower($value)] = true;
6264
$path_parts = pathinfo($value);
6365

@@ -73,7 +75,7 @@
7375
exit;
7476
}
7577
} else {
76-
error_log("Bulk Encode Error: User does not have permission to bulk encode.");
78+
error_log("Bulk Encode Error: User does not have permission.");
7779
echo json_encode(["error" => "Permission denied"]);
7880
exit;
7981
}

0 commit comments

Comments
 (0)