mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
wf work
This commit is contained in:
@@ -13,21 +13,23 @@ require dirname(__FILE__).'/../server/init.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
// Get query string parameters ?file=settings_table.json&download=true
|
||||
$file = isset($_GET['file']) ? $_GET['file'] : null;
|
||||
$download = isset($_GET['download']) ? $_GET['download'] === 'true' : false;
|
||||
$download = isset($_GET['download']) && $_GET['download'] === 'true';
|
||||
|
||||
// Check if file parameter is provided
|
||||
if ($file) {
|
||||
// Define the folder where files are located
|
||||
$filePath = "/app/config/" . basename($file);
|
||||
|
||||
// Check if the file exists
|
||||
if (file_exists($filePath)) {
|
||||
// Handle download behavior
|
||||
// Check if the file exists and is readable
|
||||
if (file_exists($filePath) && is_readable($filePath)) {
|
||||
// Determine file extension
|
||||
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
|
||||
|
||||
if ($download) {
|
||||
// Force file download
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
|
||||
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
@@ -35,19 +37,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
readfile($filePath);
|
||||
exit;
|
||||
} else {
|
||||
// Display file content
|
||||
header('Content-Type: text/plain');
|
||||
echo file_get_contents($filePath);
|
||||
// Serve file based on type
|
||||
if ($extension === 'json') {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(json_decode(file_get_contents($filePath), true), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
header('Content-Type: text/plain');
|
||||
echo file_get_contents($filePath);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// File not found response
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["error" => "File not found"]);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// Missing file parameter response
|
||||
http_response_code(400);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["error" => "Missing 'file' parameter"]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user