<?php
include 'config.php';

if ($_POST['auth_token'] !== AUTH_TOKEN) {
    die(json_encode(["error" => "Unauthorized"]));
}

$type = $_POST['type'];
$filename = $_POST['filename'];

$folder = ($type === 'shram') ? APP_DIR : (($type === 'admin') ? APP_DIR_ADMIN : null);

if (!$folder || !$filename) {
    die(json_encode(["error" => "Invalid parameters"]));
}

$fullPath = $folder . basename($filename);

if (file_exists($fullPath)) {
    echo json_encode(["exists" => true]);
} else {
    echo json_encode(["exists" => false]);
}
?>