ok
Direktori : /home2/selectio/public_html/thedentalpark.com/admin/ |
Current File : /home2/selectio/public_html/thedentalpark.com/admin/banner-add.php |
<?php include("header.php"); if(isset($_POST['add_banner'])) { try { // Database connection assumed to be initialized as $pdo // Date for appending to image file name $date = date("Y-m-d"); // Handle file upload if(isset($_FILES['banner']) && $_FILES["banner"]["name"] != "") { $file_name = $_FILES['banner']['name']; $tmp = explode('.', $file_name); $extension = end($tmp); // Get the file extension $image = uniqid() . "-" . $date . "-org_signature." . $extension; // Generate unique file name $upload_path = '../upload/banner/' . $image; // Move uploaded file to destination directory if(move_uploaded_file($_FILES['banner']['tmp_name'], $upload_path)) { $banner = 'upload/banner/' . $image; // Save path to database } else { throw new Exception('Failed to move uploaded file.'); } } else { throw new Exception('No file uploaded.'); } // Insert banner path into database using prepared statement $statement = $pdo->prepare("INSERT INTO `tbl_banner` (`banner_images`) VALUES (:banner)"); $statement->bindParam(':banner', $banner); $result = $statement->execute(); // Check result of database operation if($result) { echo '<script type="text/javascript"> alert("New Banner Added successfully"); window.location.href = "banner-details.php"; </script>'; exit; // Exit to prevent further execution } else { throw new Exception('Failed to insert banner into database.'); } } catch(Exception $e) { // Handle errors echo '<script type="text/javascript"> alert("Error: '.$e->getMessage().'"); window.location.href = "banner-add.php"; </script>'; } } ?> <div class="content-wrapper" style="background:white;"> <div class="clearfix"></div> <section class="content"> <div class="row"> <div class="col-xs-12"> <div> <div class="box-header"> <h3 class="box-title"><b>Add New Banner Image: </b></h3> </div> <div class="box-body"> <div class="col-lg-12"> <!--<div id="loading-div"> <center><img src="assets/load.gif" style="10%"><br> <strong class="blink_me">Loading Pls Wait... </strong></center> </div> <div id="success-div"> </div>--> <div id="content-div"> <form action="" enctype="multipart/form-data" method="post" id="slider_form" accept-charset="utf-8"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="optional" for="title">Silder Title</label> <input type="text" name="title" id="title" value="" placeholder="Enter Silder Title" class="form-control" /> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="required" for="banner_img">Choose The Banner Image</label> <span>(Recommanded Size 1920*1280)</span> <input type="file" name="banner_img" id="banner_img" value="" placeholder="Choose The banner Image" class="form-control tip" required="required" /> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="optional" for="short_description">Silder Short Description</label> <textarea name="short_description" id="short_description" value="" placeholder="Enter Silder Short Description" class="form-control"></textarea> </div> </div> <!--<div class="col-md-6">--> <!-- <div class="form-group">--> <!-- <label class="required" for="file">Category</label> --> <!-- <select name="category" id="category" class="form-control">--> <!-- <option value="">Select Category</option>--> <!-- <option value="home">Home Page</option>--> <!-- <option value="about">About Page</option>--> <!-- <option value="gallery">Gallery Page</option>--> <!-- <option value="contact">Contact Page</option--> <!-- </select>--> <!-- </div>--> <!--</div>--> </div> <div class="row"> <div class="form-group" style="text-align:center;"> <!--<label class="required" for="file">Action</label><br>--> <button type="submit" id="submit_slider" name="submit_slider" class="btn btn-success">Add Slider</button> </div> </div> </form> </div> <div class="form-group" style="text-align:center;"> <a href="banner-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a> <a href="banner-details.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> <style> table,td,th{ padding:5px; } th{ border: 1px solid black; } td{ border: 1px solid black; border-style: dashed; } </style> <?php include "footer.php";?> <script type="text/javascript"> $(document).ready(function() { $.validator.addMethod("large_text_field",function(value,element){ if(value){ return this.optional(element) || (/[\=\<\>]+/.test(value))? false : true; }else{ return true; } },"Don't Use '=' Symbol and Tag '<>' Symbol "); $.validator.addMethod('filesize', function (value, element) { return this.optional(element) || (element.files[0].size < 2097153) }, 'File size must be less than 2mb'); $('#slider_form').validate({ rules:{ 'title': { large_text_field:true, maxlength: 100 }, 'short_description': { large_text_field:true, maxlength: 250 }, 'banner_img': { required: true, extension:'png|jpg|jpeg|webp', filesize: true }, 'category':{ required: true } }, errorPlacement: function(error, element) { var ername = element.attr('name'); error.css('color', 'red'); element.parents('.form-group').append(error); }, messages:{ 'banner_img': { extension: 'png, jpg, jpeg, webp formats only allowed' } }, submitHandler: function(form){ $('#submit_btn').attr('disabled',true).text("Processing..."); form.submit(); } }); }); </script>