<?php
header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['file'])) {
    $file = basename($_POST['file']);
    $filepath = __DIR__ . '/' . $file;
    
    // Pastikan hanya file HTML yang bisa dihapus
    if (file_exists($filepath) && pathinfo($filepath, PATHINFO_EXTENSION) === 'html') {
        if (unlink($filepath)) {
            echo json_encode(['success' => true]);
        } else {
            echo json_encode(['success' => false, 'error' => 'Gagal menghapus file']);
        }
    } else {
        echo json_encode(['success' => false, 'error' => 'File tidak ditemukan atau bukan file HTML']);
    }
} else {
    echo json_encode(['success' => false, 'error' => 'Invalid request']);
}
?>