ok
Direktori : /home2/selectio/public_html/thedentalpark.com/admin/ |
Current File : /home2/selectio/public_html/thedentalpark.com/admin/banner-edit.php |
<?php include "header.php"; if(isset($_POST['update-banner'])) { try { // Database connection assumed to be initialized as $pdo $date = date('Y-m-d'); // Use current date and time for timestamp // Handle file upload if a new file is selected if(isset($_FILES['banner_images']) && $_FILES["banner_images"]["name"] != "") { // Check file size (maximum 5 MB) $max_file_size = 20 * 1024 * 1024; // 5 MB in bytes if($_FILES['banner_images']['size'] > $max_file_size) { throw new Exception('File size exceeds the limit of 5 MB.'); } // Delete old banner image file if(file_exists($_POST['old_photo'])) { unlink($_POST['old_photo']); } // Sanitize file name to remove unwanted spaces $file_name = $_FILES['banner_images']['name']; $file_name = str_replace(' ', '_', $file_name); // Replace spaces with underscores $extension = pathinfo($file_name, PATHINFO_EXTENSION); // Get file extension $image = uniqid() . "-" . $date . "-image." . $extension; // Generate unique file name $upload_path = '../upload/banner/' . $image; // Move uploaded file to destination directory if(move_uploaded_file($_FILES['banner_images']['tmp_name'], $upload_path)) { $upload_image = 'upload/banner/' . $image; // New image path for database } else { throw new Exception('Failed to move uploaded file.'); } } else { // If no new file is uploaded, retain the existing image path $upload_image = $_POST['old_photo']; } // Prepare and execute SQL update statement $statement = $pdo->prepare("UPDATE tbl_banner SET banner_images=?, status=? WHERE id=?"); $result = $statement->execute([$upload_image, $_POST['status'], $_POST['ids']]); // Check if update was successful if($result) { echo '<script type="text/javascript"> alert("Banner Updated successfully"); window.location.href = "banner-details.php"; </script>'; exit; // Exit to prevent further execution } else { throw new Exception('Failed to update banner.'); } } catch(Exception $e) { // Handle errors echo '<script type="text/javascript"> alert("Error: '.$e->getMessage().'"); window.location.href = "banner-details.php"; // Redirect to appropriate page </script>'; } } $ids=$_GET['id']; $statement = $pdo->prepare("SELECT * FROM tbl_banner WHERE id=".$ids); $statement->execute(); $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); $date = date('d-m-Y'); if($totalData==1){ ?> <div class="content-wrapper" style="background:white;"> <section class="content-header"> <h4><b>Update Banner Image</b></h4> <ol class="breadcrumb"> <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Update Banner Image</li> </ol> </section> <section class="content"> <div class="row"> <div class="col-xs-12"> <div> <div class="box-body"> <div class="col-lg-12"> <form action="" class="validation" enctype="multipart/form-data" method="post" accept-charset="utf-8"> <input type="hidden" name="ids" value="<?=$emp_data[0]['id']?>" class="form-control tip" id="id" required="required" /> <?php foreach($emp_data as $data){ ?> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="desgination">Gallery Image</label> <?php if($emp_data[0]['banner_images']==''){ ?> <img src="upload/default-photo.png" class="img-thumbnail" alt="" style="width: 100%;height:180px;"> <?php }else{ ?> <img src="../<?=$data['banner_images']?>" class="img-thumbnail" alt="" style="width: 100%;height:180px;"> <?php } ?> <input type="file" name="banner_images" placeholder="Photo" class="form-control tip" id="photo" /> <input type="hidden" name="old_photo" value="<?=$data['banner_images']?>" class="form-control tip" id="old_photo" /> </div> <span style="color: red;" id="photospan"></span> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="status">Status</label> <select name="status" id="status" class="form-control tip select2"> <option value="1" <?php if($data['status']==1){ echo "selected";} ?>>Active</option> <option value="0" <?php if($data['status']==0){ echo "selected";} ?>>In-Active</option> </select> </div> </div> </div> <?php } ?> <div class="form-group" style="text-align:center;"> <input type="submit" name="update-banner" value="Update Banner Image" class="btn btn-success" /> </form> </div> </div> <div class="form-group" style="text-align:center;"> <?php echo "<a href=gallery-edit.php?id=".$ids."> <button class='btn btn-primary' > <i class='fa fa-refresh'></i> Reset Form</button></a>"; ?> <a href="gallery.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a> </div> <div class="clearfix"></div> </div> </div> </div> </div> </section> <script> var photo = document.getElementById("photo"); photo.onchange = function() { console.log(photo); $('#photospan').text(''); if(this.files[0].size > 55000000000){ $('#photospan').text('Photo Image Maximum 5 mb Allowed'); alert("File is too big!"); this.value = ""; }; }; </script> <?php } include "footer.php";?>