ok
Direktori : /home2/selectio/www/thedentalpark.com/admin/ |
Current File : /home2/selectio/www/thedentalpark.com/admin/gallery-add.php |
<?php include "header.php";?> <?php if(isset($_POST['add_gallery'])){ try { $date = date("Y-m-d"); $category = $_POST['category']; $total_Count = count($_FILES["gallery_image"]["name"]); // Loop through each uploaded file for($i = 0; $i < $total_Count; $i++){ if(isset($_FILES['gallery_image']['name'][$i]) && $_FILES["gallery_image"]["name"][$i] != ""){ // Process the uploaded file $file_name = $_FILES['gallery_image']['name'][$i]; $tmp = explode('.', $file_name); $extension = end($tmp); $image = rand(10, 1000000000) . "-" . date("YmdHis") . "-org_signature." . $extension; // Upload the file $upload = move_uploaded_file($_FILES['gallery_image']['tmp_name'][$i], '../upload/gallery/' . $image); if($upload){ $banner = 'upload/gallery/' . $image; // Prepare SQL statement to insert image path into database $statement = $pdo->prepare("INSERT INTO `tbl_gallery`(`gallery_images`,`category_id`) VALUES (?,?)"); $result = $statement->execute([$banner,$category]); if(!$result){ throw new Exception("Failed to insert image path into database."); } } else { throw new Exception("Failed to upload file: " . $_FILES['gallery_image']['name'][$i]); } } } // Redirect after successful submission header("Location: gallery-details.php"); exit(); } catch(Exception $e){ $error = $e->getMessage(); echo '<script type="text/javascript">alert("Error: ' . $error . '");</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 Gallery 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" accept-charset="utf-8"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="category">Select Category</label> <select name="category" id="category" class="form-control tip select2"> <option value = "0" >Select Any Category</option> <?php $statement = $pdo->prepare("SELECT * FROM tbl_gallery_category WHERE status=1 ORDER BY id DESC"); $statement->execute(); $category_data = $statement->fetchAll(PDO::FETCH_ASSOC); $total_rows = $statement->rowCount(); if($total_rows>0){ foreach($category_data as $category_datas){ ?> <option value = "<?=$category_datas['id']?>"><?=$category_datas['category_name'] ?></option> <?php } } ?> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="file">Choose The Gallery Image</label> <input type="file" name="gallery_image[]" id="photo" value="" accept="image/png, image/gif, image/jpeg" class="form-control tip" required="required" multiple /> </div> <span style="color: red;" id="photospan"></span> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="file">Action</label><br> <input type="submit" id="add_category" name="add_gallery" value="Add Gallery" class="btn btn-success" /> </div> </div> </div> </form> </div> <div class="form-group" style="text-align:center;"> <a href="gallery-add.php"><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> <style> table,td,th{ padding:5px; } th{ border: 1px solid black; } td{ border: 1px solid black; border-style: dashed; } </style> <?php include "footer.php";?>