-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-public-folder-data.php
More file actions
70 lines (56 loc) · 2.13 KB
/
Copy pathget-public-folder-data.php
File metadata and controls
70 lines (56 loc) · 2.13 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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$request_headers = apache_request_headers();
$http_origin = '';
// If Origin header exists, capture it
if (isset($request_headers['Origin'])) {
$http_origin = $request_headers['Origin'];
}
// Allow all origins
header("Access-Control-Allow-Origin: *");
// Allow the specified methods
header("Access-Control-Allow-Methods: POST, GET, OPTIONS");
// Allow the specified headers
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
// Handle preflight requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
// The request is a preflight request. Respond successfully:
http_response_code(200);
exit;
}
include('./db-connection.php'); // Include the database connection code
$data = file_get_contents('php://input');
$data = json_decode($data);
$path = $data->path;
// Retrieve the 'path' parameter from the POST data
if ($path !== null) {
try {
$sql = "SELECT * FROM `folders` WHERE JSON_CONTAINS(`access_level`, '10') AND `path` = ? ORDER BY `date` DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $path);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
$folder = $result->fetch_assoc();
$filtered_folder = [
'folder_name' => $folder['name'],
'path' => $folder['path'],
'parent_path' => $folder['parent_path']
];
echo json_encode($filtered_folder);
} else {
http_response_code(404); // User not found
echo json_encode(['error' => 'Folder not found']);
}
} catch (Exception $e) {
http_response_code(500); // Server error
echo json_encode(['error' => 'Server error']);
// Log the error if needed
}
} else {
http_response_code(400); // Bad request
echo json_encode(['error' => 'Invalid request']);
}
?>