|
8 | 8 | ini_set('log_errors', 1);
|
9 | 9 |
|
10 | 10 | if (empty($global['allowed'])) {
|
11 |
| - $global['allowed'] = array(); |
| 11 | + $global['allowed'] = []; |
12 | 12 | }
|
13 | 13 |
|
14 |
| -// Ensure extensions are in lowercase and unique |
15 | 14 | $global['allowed'] = array_map('strtolower', $global['allowed']);
|
16 | 15 | $global['allowed'] = array_unique($global['allowed']);
|
17 | 16 |
|
18 |
| -$files = array(); |
| 17 | +$files = []; |
19 | 18 |
|
20 | 19 | if (Login::canBulkEncode()) {
|
21 | 20 | 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"]); |
30 | 25 | exit;
|
31 | 26 | }
|
| 27 | + $path .= DIRECTORY_SEPARATOR; |
| 28 | + error_log("Bulk Encode: Resolved path - " . $path); |
32 | 29 |
|
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"]); |
36 | 33 | exit;
|
37 | 34 | }
|
38 | 35 |
|
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 | + } |
46 | 48 | }
|
47 |
| - $video_array = array_merge($video_array, $filesFound); |
| 49 | + } else { |
| 50 | + error_log("Bulk Encode Error: scandir() failed for " . $path); |
48 | 51 | }
|
49 | 52 |
|
50 | 53 | 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."); |
52 | 55 | }
|
53 | 56 |
|
54 | 57 | $addedFiles = [];
|
|
57 | 60 | if (isset($addedFiles[strtolower($value)])) {
|
58 | 61 | continue;
|
59 | 62 | }
|
60 |
| - |
61 | 63 | $addedFiles[strtolower($value)] = true;
|
62 | 64 | $path_parts = pathinfo($value);
|
63 | 65 |
|
|
73 | 75 | exit;
|
74 | 76 | }
|
75 | 77 | } 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."); |
77 | 79 | echo json_encode(["error" => "Permission denied"]);
|
78 | 80 | exit;
|
79 | 81 | }
|
|
0 commit comments