<?php
$uploadDir = __DIR__ . 'https://senarulodge.com/uploads/';
$uploadUrl = 'https://senarulodge.com/uploads/';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['filename'])) {
    $filename = basename($_POST['filename']);
    $targetFile = $uploadDir . $filename;

    // Debugging: Cek nilai filename yang diterima
    var_dump($filename);  // Menampilkan nama file yang diterima
    var_dump($targetFile);  // Menampilkan path lengkap file yang akan dihapus

    if (file_exists($targetFile)) {
        if (unlink($targetFile)) {
            $response = [
                'deleted' => true,
                'message' => 'File berhasil dihapus.'
            ];
        } else {
            $response = [
                'deleted' => false,
                'error' => ['message' => 'Gagal menghapus file.']
            ];
        }
    } else {
        $response = [
            'deleted' => false,
            'error' => ['message' => 'File tidak ditemukan.']
        ];
    }

    // Kirim respons dalam format JSON
    header('Content-Type: application/json');
    echo json_encode($response);
    exit;
}
?>
