관리-도구
편집 파일: insert.php
<?php include('include/head_admin.php'); $category = ''; $url = ''; $plans = ''; $tours = ''; $dham_yatra = ''; $domestic = ''; $weekend = ''; $name = ''; $title = ''; $short_description = ''; $image = ''; $image_alt_tag = ''; $days = ''; $price = ''; $description = ''; $map = ''; $meta_title = ''; $meta_description = ''; $keyword = ''; $canonical_tag = ''; if (isset($_POST['submit'])) { $plans = isset($_POST['plans']) ? 1 : 0; $tours = isset($_POST['tours']) ? 1 : 0; $dham_yatra = isset($_POST['dham_yatra']) ? 1 : 0; $domestic = isset($_POST['domestic']) ? 1 : 0; $weekend = isset($_POST['weekend']) ? 1 : 0; $category = get_safe_value($con, $_POST['category']); $name = get_safe_value($con, $_POST['name']); $url = generate_seo_friendly_title($name); $title = get_safe_value($con, $_POST['title']); $short_description = get_safe_value($con, $_POST['short_description']); $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']); $days = get_safe_value($con, $_POST['days']); $price = get_safe_value($con, $_POST['price']); $description = get_safe_value($con, $_POST['description']); $map = get_safe_value($con, $_POST['map']); $meta_title = get_safe_value($con, $_POST['meta_title']); $meta_description = get_safe_value($con, $_POST['meta_description']); $keyword = get_safe_value($con, $_POST['keyword']); $canonical_tag = get_safe_value($con, $_POST['canonical_tag']); $image_array = $_FILES['image']; $image_count = count($image_array['name']); $array = array(); for ($i = 0; $i < $image_count; $i++) { $image_name = rand(111111111, 999999999) . '_' . $image_array['name'][$i]; $image_tmp_name = $image_array['tmp_name'][$i]; $image_size = $image_array['size'][$i]; $image_error = $image_array['error'][$i]; $image_type = $image_array['type'][$i]; array_push($array, $image_name); // Upload the image to your desired location move_uploaded_file($image_tmp_name, '../media/package/' . $image_name); } $package_images = json_encode($array); $insert_query = "INSERT INTO `package`(`url`, `category`, `plans`, `tours`, `dham_yatra`, `domestic`, `weekend`, `name`, `title`, `short_description`, `image`, `image_alt_tag`, `days`, `price`, `description`, `map`, `meta_title`, `meta_description`, `keyword`, `canonical_tag`) VALUES ('$url','$category','$plans','$tours','$dham_yatra','$domestic','$weekend','$name','$title','$short_description','$package_images','$image_alt_tag','$days','$price','$description','$map','$meta_title','$meta_description','$keyword','$canonical_tag')"; mysqli_query($con, $insert_query); // print_r($insert_query); header('location: all-package.php'); die(); } if (isset($_POST['update_package_submit'])) { $id = $_POST['id']; $plans = isset($_POST['plans']) ? 1 : 0; $tours = isset($_POST['tours']) ? 1 : 0; $dham_yatra = isset($_POST['dham_yatra']) ? 1 : 0; $domestic = isset($_POST['domestic']) ? 1 : 0; $weekend = isset($_POST['weekend']) ? 1 : 0; $category = get_safe_value($con, $_POST['category']); $name = get_safe_value($con, $_POST['name']); $url = generate_seo_friendly_title($name); $title = get_safe_value($con, $_POST['title']); $short_description = get_safe_value($con, $_POST['short_description']); $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']); $days = get_safe_value($con, $_POST['days']); $price = get_safe_value($con, $_POST['price']); $description = get_safe_value($con, $_POST['description']); $map = get_safe_value($con, $_POST['map']); $meta_title = get_safe_value($con, $_POST['meta_title']); $meta_description = get_safe_value($con, $_POST['meta_description']); $keyword = get_safe_value($con, $_POST['keyword']); $canonical_tag = get_safe_value($con, $_POST['canonical_tag']); // Check if new images are provided if (isset($_FILES['image'])) { // Fetch existing images from the database $row = mysqli_query($con, "SELECT * FROM `package` WHERE `id`='$id'"); $result = mysqli_fetch_assoc($row); $old_images = json_decode($result['image'], true); // Decode JSON array $new_images = []; // Loop through the new images foreach ($_FILES['image']['name'] as $key => $value) { // Check if the file field is not empty if (!empty($_FILES['image']['name'][$key])) { $new_image_name = rand(111111111, 999999999) . '_' . $_FILES['image']['name'][$key]; $new_image_tmp_name = $_FILES['image']['tmp_name'][$key]; move_uploaded_file($new_image_tmp_name, '../media/package/' . $new_image_name); $new_images[] = $new_image_name; } else { // If no new image was uploaded for this index, add the corresponding old image $new_images[] = $old_images[$key] ?? ''; } } // Encode the modified array of image names as JSON $package_image = json_encode($new_images); } else { // If no new images were provided, keep the existing images $package_image = $result['image']; } // Update the package information in the database $update_sql = "UPDATE `package` SET `url`='$url',`category`='$category',`plans`='$plans',`tours`='$tours',`dham_yatra`='$dham_yatra',`domestic`='$domestic',`weekend`='$weekend',`name`='$name',`title`='$title',`short_description`='$short_description',`image`='$package_image',`image_alt_tag`='$image_alt_tag',`days`='$days',`price`='$price',`description`='$description',`map`='$map',`meta_title`='$meta_title',`meta_description`='$meta_description',`keyword`='$keyword',`canonical_tag`='$canonical_tag' WHERE `id`='$id'"; mysqli_query($con, $update_sql); header('location: all-package.php'); } function generate_seo_friendly_title($title) { // Convert the title to lowercase $title = strtolower($title); // Replace spaces with dashes $title = str_replace(' ', '-', $title); // Remove special characters $title = preg_replace('/[^A-Za-z0-9\-]/', '', $title); return $title; }