isDir() ? @rmdir($item->getPathname()) : @unlink($item->getPathname()); } @rmdir($dir); } $type = $_POST['type'] ?? ''; if ($type === 'repo') { $id = (int) ($_POST['id'] ?? 0); $repo = get_repository($id); if ($repo) { remove_upload_dir($repo['slug']); delete_repository($id); // cascades file + folder rows } header('Location: ' . url('/admin/dashboard.php?deleted=1')); exit; } if ($type === 'folder') { $id = (int) ($_POST['id'] ?? 0); $folder = get_folder($id); if ($folder) { $repo = get_repository((int) $folder['repo_id']); $path = delete_folder($id); // removes descendant file + folder rows if ($repo && $path !== null) { remove_upload_dir($repo['slug'] . '/' . $path); } if ($repo) { header('Location: ' . url('/admin/upload.php?repo=' . urlencode($repo['slug']) . '&deleted=1')); exit; } } header('Location: ' . url('/admin/dashboard.php?deleted=1')); exit; } if ($type === 'file') { $id = (int) ($_POST['id'] ?? 0); $file = get_file($id); if ($file) { $repo = get_repository((int) $file['repo_id']); // Delete the file on disk, guarding against traversal. $base = realpath(UPLOAD_DIR); $full = realpath(UPLOAD_DIR . '/' . $file['filepath']); if ($base !== false && $full !== false && strpos($full, $base . DIRECTORY_SEPARATOR) === 0) { @unlink($full); } delete_file($id); if ($repo) { header('Location: ' . url('/admin/upload.php?repo=' . urlencode($repo['slug']) . '&deleted=1')); exit; } } header('Location: ' . url('/admin/dashboard.php?deleted=1')); exit; } http_response_code(400); exit('Unknown delete type.');