<?php

// Allow CORS for API calls from Flutter
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

if (!isset($_GET['folder'])) {
    echo json_encode(["error" => "Folder parameter is missing."]);
    exit;
}

$folder = basename($_GET['folder']); // Prevent directory traversal attacks
$directory = __DIR__ . "/storage/$folder"; // Correct folder path

if (!is_dir($directory)) {
    echo json_encode(["error" => "Directory not found."]);
    exit;
}

// Get all files in the folder
$files = array_diff(scandir($directory), array('.', '..'));
echo json_encode(array_values($files));

?>
