Repository navigation
Expand file tree
/
Copy pathlistFiles.json.php
More file actions
83 lines (71 loc) · 2.58 KB
/
Copy pathlistFiles.json.php
File metadata and controls
83 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once dirname(__FILE__) . '/../videos/configuration.php';
require_once $global['systemRootPath'] . 'objects/Login.php';
header('Content-Type: application/json');
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
if (empty($global['allowed'])) {
$global['allowed'] = [];
}
$global['allowed'] = array_map('strtolower', $global['allowed']);
$global['allowed'] = array_unique($global['allowed']);
$files = [];
if (Login::canBulkEncode()) {
if (!empty($_POST['path'])) {
$path = realpath($_POST['path']);
if ($path === false) {
error_log("Bulk Encode Error: realpath() failed for " . $_POST['path']);
echo json_encode(["error" => "Invalid path"]);
exit;
}
$path .= DIRECTORY_SEPARATOR;
error_log("Bulk Encode: Resolved path - " . $path);
if (!file_exists($path) || !is_readable($path)) {
error_log("Bulk Encode Error: Path not accessible - " . $path);
echo json_encode(["error" => "Path not accessible"]);
exit;
}
$video_array = [];
$dirContents = scandir($path);
if ($dirContents !== false) {
foreach ($dirContents as $file) {
$filePath = $path . $file;
if (is_file($filePath)) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
if (in_array($ext, $global['allowed'])) {
$video_array[] = $filePath;
}
}
}
} else {
error_log("Bulk Encode Error: scandir() failed for " . $path);
}
if (empty($video_array)) {
error_log("Bulk Encode Warning: No files found.");
}
$addedFiles = [];
$id = 0;
foreach ($video_array as $value) {
if (isset($addedFiles[strtolower($value)])) {
continue;
}
$addedFiles[strtolower($value)] = true;
$path_parts = pathinfo($value);
$obj = new stdClass();
$obj->id = $id++;
$obj->path = mb_convert_encoding($value, 'UTF-8');
$obj->name = mb_convert_encoding($path_parts['basename'], 'UTF-8');
$files[] = $obj;
}
} else {
error_log("Bulk Encode Error: No path provided.");
echo json_encode(["error" => "No path provided"]);
exit;
}
} else {
error_log("Bulk Encode Error: User does not have permission.");
echo json_encode(["error" => "Permission denied"]);
exit;
}
echo json_encode($files);