2025-06-05 08:52:31 +02:00
|
|
|
<?php
|
2025-06-19 23:14:18 +02:00
|
|
|
header('Content-Type: application/json');
|
2025-06-05 08:52:31 +02:00
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
|
|
echo json_encode(['success' => false, 'error' => 'Invalid request method']);
|
2025-06-05 08:52:31 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
|
|
|
|
$path = $_SERVER['DOCUMENT_ROOT'] . '/' . $data['path'];
|
2025-06-05 08:52:31 +02:00
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
if (!file_exists($path)) {
|
|
|
|
echo json_encode(['success' => false, 'error' => 'File/folder does not exist']);
|
2025-06-05 08:52:31 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
// Check if it's a directory
|
|
|
|
if (is_dir($path)) {
|
|
|
|
// Delete recursively
|
|
|
|
deleteDirectory($path);
|
|
|
|
} else {
|
|
|
|
unlink($path);
|
2025-06-05 08:52:31 +02:00
|
|
|
}
|
|
|
|
|
2025-06-19 23:14:18 +02:00
|
|
|
echo json_encode(['success' => true]);
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
function deleteDirectory($dir) {
|
|
|
|
if (!is_dir($dir)) return;
|
|
|
|
|
|
|
|
$files = scandir($dir);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file === '.' || $file === '..') continue;
|
|
|
|
$path = $dir . '/' . $file;
|
|
|
|
is_dir($path) ? deleteDirectory($path) : unlink($path);
|
|
|
|
}
|
|
|
|
rmdir($dir);
|
2025-06-05 08:52:31 +02:00
|
|
|
}
|
2025-06-19 23:14:18 +02:00
|
|
|
?>
|