D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home2
/
technoi4
/
www
/
admin
/
Filename :
product_image.php
back
Copy
<?php require_once('header.php'); require_once('config.php'); ?> <head> <title>Techno_Gulf | Product_Image</title> </head> <body> <?php require('sidebar.php'); ?> <main class="page-content"> <div class="container-fluid"> <h2>Add Product_Image</h2> <hr> <div class="btn btn-group"> <button id="one" class="btn btn-group btn-primary">INSERT</button> <button id="two" class="btn btn-group btn-danger">VIEW</button> </div> <div class="mt-5"></div> <div class="on"> <form method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label for="exampleInputPassword1">Product_Name</label> <select class="form-control" name="pid"> <option value="">Select Product_Name</option> <?php require('config.php'); $result = mysqli_query($conn,"SELECT * FROM product"); while($row = mysqli_fetch_array($result)) { ?> <option value="<?php echo $row['pid'];?>"><?php echo $row["product_name"];?></option> <?php } ?> </select> </div> <div class="form-group"> <label for="exampleFormControlFile1">Image File</label> <input type="file" class="form-control-file" name="image[]" multiple> </div> <button type="submit" name="add" class="btn btn-warning">Add</button> </div> </div> </form> </div> <div class="to"> <div id="buttons"></div> <!-- Table --> <table id="product" class="table table-striped table-hover dt-responsive" cellspacing="0" width="100%"> <thead> <tr> <th>Id </th> <th>Product Name </th> <th>Image File </th> <th>Edit</th> <th>Delete</th> </tr> </thead> </table> </div> </div> <?php if (isset($_POST['add'])) { $pid = $_POST['pid']; $image = $_FILES['image']['name']; $is_deleted = 0; $dir = 'img/product_image/'; foreach ($_FILES['image']['tmp_name'] as $key => $image) { $imageTmpName = $_FILES['image']['tmp_name'][$key]; $imageName = $_FILES['image']['name'][$key]; $result = move_uploaded_file($imageTmpName,$dir.$imageName); require('config.php'); // save to database $query = "INSERT INTO `product_image`(`pid`, `image`, `is_deleted`) values ('$pid', '$imageName', '$is_deleted')" ; $run = $conn->query($query) or die("Error in saving image".$conn->error); } if ($result) { echo '<script>alert("Images uploaded successfully !")</script>'; echo '<script>window.location.href="product_image.php";</script>'; } } ?> </main> <!-- Script --> <script> $(document).ready(function () { var dataTable = $('#product').DataTable({ 'processing': true, 'serverSide': true, "responsive": true, 'serverMethod': 'post', "lengthMenu": [[10, 25, 50, 100,500,1000], [10, 25, 50,100,500,1000]], 'dom': 'Blfrtip', 'buttons': [ ], 'ajax': { 'url':'productfile.php', }, 'columns': [ { data: 'id' }, { data: 'product_name' }, { data: 'image' }, { data: 'edit' }, { data: 'delete' }, ] }); }); $(document).ready(function() { $('#product').DataTable(); $(".on").hide(); console.log("ready!"); $("#one").click(function() { $(".on").show(); $(".to").hide(); }); $("#two").click(function() { $(".to").show(); $(".on").hide(); }); }); </script> <script> $('#selector').change(function(){ if($(this).val() == "no" ){ $('.otherprof').slideUp(); }else{ $('.otherprof').slideDown(); } }); </script> <script> $('#selector_new').change(function(){ if($(this).val() == "no" ){ $('.other_prof').slideUp(); }else{ $('.other_prof').slideDown(); } }); </script> <?php include('footer.php'); ?>