hjkhghoppoopppooppoppoppoopoirh
bnmbertsurheoppopopooooooooooooooopoopopdf'tdfg
/
home
/
u641149403
/
domains
/
cabz4you.com
/
public_html
/
admin
/
Upload FileeE
HOME
<?php include 'lib/core.php'; //Show All local_rental if ($_SERVER['REQUEST_METHOD'] == "GET") { if (isset($_GET['show_data'])) { $show = "SELECT * FROM local_rental"; $result = $conn->query($show); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $show_data[] = $row; } echo json_encode($show_data); } } } // Adding local_rental if (isset($_POST['title'])) { $title = $_POST['title']; $image = $_FILES['image']['name']; $directory = 'upload/local_rental/'; if (!is_dir($directory)) { mkdir($directory, 0777, true); // Create directory with full permissions } $path = $directory . time() . $image; $add = "INSERT INTO local_rental(title,image) VALUES('$title','$path')"; if ($conn->query($add)) { move_uploaded_file($_FILES['image']['tmp_name'], $path); echo "Success"; } else { echo "Something Wrong"; } } if (isset($_POST['edit_id'])) { $id = $_POST['edit_id']; $query = "SELECT * FROM local_rental WHERE id = " . $id; $result = $conn->query($query); if ($result->num_rows > 0) { $current_category = $result->fetch_assoc(); echo json_encode($current_category); } } //Updating local_rental in Modal if (isset($_POST['save_id'])) { $id = $_POST['save_id']; $title = $_POST['edit_title']; $image = $_FILES['edit_img']['name']; $directory = 'upload/local_rental/'; if (!is_dir($directory)) { mkdir($directory, 0777, true); // Create directory if it doesn't exist } // Fetch existing image path $result = $conn->query("SELECT image FROM local_rental WHERE id = $id"); $row = $result->fetch_assoc(); $existing_img = $row['image']; // If a new image is uploaded, update the path; otherwise, keep the existing one if (!empty($image)) { unlink($existing_img); $path = $directory . time() . "_" . basename($image); move_uploaded_file($_FILES['edit_img']['tmp_name'], $path); } else { $path = $existing_img; } // Update title and description regardless of image upload $sql = "UPDATE local_rental SET title='$title', image='$path' WHERE id = $id"; if ($conn->query($sql)) { echo "Success"; } else { echo "Something went wrong: " . $conn->error; } } //Delete local_rental if (isset($_POST['delete_id'])) { $id = $_POST['delete_id']; $query = "DELETE FROM local_rental WHERE id = " . $id; if ($conn->query($query)) { echo "Success"; } else { echo "Something Wrong"; } } ?>