관리-도구
편집 파일: add-about.php
<!DOCTYPE html> <html lang="en" dir="ltr"> <!-- Mirrored from themes.pixelstrap.com/fastkart/back-end/add-new-category.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 10 Apr 2024 05:07:03 GMT --> <head> <?php include('include/head_admin.php'); $image = ''; $image_alt_tag = ''; $heading = ''; $description = ''; if (isset($_GET['id']) && $_GET['id'] != '') { $id = get_safe_value($con, $_GET['id']); $image_required = ''; $res = mysqli_query($con, "SELECT * from `about` where id='$id'"); $check = mysqli_num_rows($res); if ($check > 0) { $row = mysqli_fetch_assoc($res); $image = $row['image']; $image_alt_tag = $row['image_alt_tag']; $heading = $row['heading']; $description = $row['description']; } else { header('location:about.php'); die(); } } if (isset($_POST['submit'])) { $heading = get_safe_value($con, $_POST['heading']); $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']); $description = get_safe_value($con, $_POST['description']); $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/about/' . $image_name); } $about_images = json_encode($array); $insert_query = "INSERT INTO `about`(`heading`,`image`,`image_alt_tag`,`description`) VALUES ('$heading','$about_images','$image_alt_tag','$description')"; mysqli_query($con, $insert_query); header('location: about.php'); die(); } if (isset($_POST['update_submit'])) { $id = $_POST['id']; $heading = get_safe_value($con, $_POST['heading']); $image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']); $description = get_safe_value($con, $_POST['description']); // Check if new images are provided if (isset($_FILES['image'])) { // Fetch existing images from the database $row = mysqli_query($con, "SELECT * FROM `about` 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/about/' . $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 $about_image = json_encode($new_images); } else { // If no new images were provided, keep the existing images $about_image = $result['image']; } // Update the about information in the database $update_sql = "UPDATE `about` SET `heading`='$heading',`image`='$about_image',`image_alt_tag`='$image_alt_tag', `description`='$description' WHERE `id`='$id'"; mysqli_query($con, $update_sql); header('location: about.php'); } ?> </head> <body> <!-- tap on top start --> <div class="tap-top"> <span class="lnr lnr-chevron-up"></span> </div> <!-- tap on tap end --> <!-- page-wrapper start --> <div class="page-wrapper compact-wrapper" id="pageWrapper"> <!-- Page Header Start--> <?php include('include/header_admin.php'); ?> <!-- Page Header Ends--> <!-- Page Body start --> <div class="page-body-wrapper"> <!-- Page Sidebar Start--> <?php include('include/sidebar_admin.php'); ?> <!-- Page Sidebar Ends--> <div class="page-body"> <!-- New about Add Start --> <div class="container-fluid"> <div class="row"> <div class="col-12"> <div class="row"> <div class="col-sm-8 m-auto"> <div class="card"> <div class="card-body"> <div class="card-header-2"> <h5>About Details</h5> </div> <form method="post" enctype="multipart/form-data"> <div class="theme-form theme-form-2 mega-form"> <?php if (isset($_GET['id'])) { ?> <div class="mb-4 row align-items-center" id="image_box"> <label class="col-sm-3 col-form-label form-label-heading">Images</label> <?php $all_image = json_decode($image); for ($i = 0; $i < count($all_image); $i++) { ?> <div class="col-sm-6" id="image_container_<?= $i; ?>"> <input class="form-control form-choose" name="image[]" type="file" id="formFile_<?= $i; ?>"> <img src="../media/about/<?= $all_image[$i] ?>" alt="" style="width: 100px"> </div> <div class="col-lg-3"> <button type="button" class="btn btn-sm btn-danger mt-2" onclick="remove_existing_image(<?= $i; ?>)"> <span id="payment-button-amount">Remove</span> </button> </div> <?php } ?> <div class="col-lg-3"> <button type="button" class="btn btn-sm btn-info mt-2" onclick="add_more_images()"> <span id="payment-button-amount">Add Image</span> </button> </div> </div> <?php } else { ?> <div class="mb-4 row align-items-center" id="image_box"> <label class="col-sm-3 col-form-label form-label-heading">Images</label> <div class="col-sm-6"> <input class="form-control form-choose" name="image[]" type="file" id="formFile_1"> </div> <div class="col-lg-3"> <button type="button" class="btn btn-sm btn-info mt-2" onclick="add_more_images()"> <span id="payment-button-amount">Add Image</span> </button> </div> </div> <?php } ?> <div class="mb-4 row align-items-center"> <label class="form-label-heading col-sm-3 mb-0">Image Alt Tag</label> <div class="col-sm-9"> <input class="form-control" name="image_alt_tag" type="text" placeholder="Image Alt Tag" value="<?= $image_alt_tag ?>"> </div> </div> <div class="mb-4 row align-items-center"> <label class="form-label-heading col-sm-3 mb-0">Heading</label> <div class="col-sm-9"> <input class="form-control" name="heading" type="text" placeholder="Heading" value="<?= $heading ?>"> </div> </div> <div class="row"> <label class="form-label-heading col-sm-12 mb-0"> Description</label> <div class="col-sm-12"> <textarea id="editor" name="description"><?= $description ?></textarea> </div> </div> </div> <?php if (isset($_GET['id'])) { ?> <input type="hidden" name="id" value="<?= $id ?>"> <button class="btn btn-solid" name="update_submit" type="submit">Update</button> <?php } else { ?> <button class="btn btn-solid" name="submit" type="submit">Submit</button> <?php } ?> </form> </div> </div> </div> </div> </div> </div> </div> <!-- New about Add End --> <!-- footer Start --> <?php include('include/footer_admin.php'); ?> <!-- footer En --> </div> <!-- Container-fluid End --> </div> <!-- Page Body End --> </div> <!-- page-wrapper End --> <?php include('include/foot_admin.php'); ?> <script> var total_image = <?php echo isset($_GET['id']) ? count($all_image) : 1; ?>; function add_more_images() { total_image++; var html = '<div class="row" id="add_image_box_' + total_image + '" ><div class="col-lg-3"></div><div class="col-lg-6">' + '<input class="form-control form-choose" type="file" name="image[]" id="formFile_' + total_image + '"></div>' + '<div class="col-lg-3"><button type="button" ' + 'class="btn btn-sm btn-danger btn-info mt-2" onclick="remove_image(' + total_image + ')">' + '<span id="payment-button-amount">Remove</span></button>' + '</div></div>'; jQuery('#image_box').append(html); } function remove_image(id) { jQuery('#add_image_box_' + id).remove(); } function remove_existing_image(id) { jQuery('#image_container_' + id).remove(); } </script> </body> <!-- Mirrored from themes.pixelstrap.com/fastkart/back-end/add-new-category.html by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 10 Apr 2024 05:07:04 GMT --> </html>