D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafrica
/
spre.dominicaninstitute.edu.ng
/
Filename :
addgallery.php
back
Copy
<?php session_start(); include 'inc/config.php'; if (!isset($_SESSION['manager'])) { header('location: ./admin-auth'); exit(); } $page_title; $page_title = ucfirst(basename(__FILE__, '.php')); if ($page_title === 'index') { $page_title = 'Home'; } $page_title = "Administator's Dashboard"; include 'sections/pages-header.php'; $message = ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if (isset($_GET['picture_id'])) { $sn = $_GET['picture_id']; $sql = "DELETE FROM gallery WHERE id='$sn'"; if (mysqli_query($con, $sql)) { $message = 'Picture deleted successfully!'; $_GET['slider_id'] = ''; } else { $message = 'Error deleting picture: ' . mysqli_error($con); } } ?> <div class="container" style="margin-top:50px"> <div> <a href="./mod-auth"><h2>Back to Admin Dashboard</h2></a> </div> <hr> <div> <h1>Add Picture</h1> <?php if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_picture']) ) { $heading = $caption = $button_text = $slider = ''; $caption = test_input($_POST['caption']); $file_name = $_FILES['slider']['name']; $file_path = 'uploads/gallery/' . $file_name; move_uploaded_file($_FILES['slider']['tmp_name'], $file_path); $feedback = "INSERT INTO gallery (caption, image) VALUES ('$caption','$file_name')"; $run = mysqli_query($con, $feedback); if ($feedback) { echo "<div class='alert alert-success alert-dismissible' role='alert'> Picture Added Successfully! </div>"; } else { echo "<div class='alert alert-danger alert-dismissible' role='alert'> An error occured, please try again! </div>"; } } ?> <br> <form action="<?php echo htmlspecialchars( $_SERVER['PHP_SELF'] ); ?>" method="post" enctype="multipart/form-data"> <div class="row clearfix"> <div class="col-md-6 col-sm-6 col-xs-12"> <!--<div class="form-group">--> <!-- <input type="text" name="caption" class="form-control" placeholder="Caption" required>--> <!--</div>--> <div class="form-group"> <p> Image Dimension 1280 x 960</p> <input type="file" name="slider" class="form-control" size="60" required> </div> <div class="form-group"> <input type="submit" name="add_picture" value="Add Picture" class="thm-btn thm-color width-100"/> </div> </div> </div> </form> </div> <hr> <div> <h1>Existing Gallery Pictures</h1> <?php if (!empty($message)): ?> <div class='alert alert-danger alert-dismissible show' role="alert"> <?= $message ?> </div> <?php endif; ?> <?php include_once './inc/config.php'; $serial = 0; $sql = 'SELECT * FROM gallery'; $result = mysqli_query($con, $sql); ?> <table id="example" class="display" style="width:100%"> <thead> <tr> <th>S/N</th> <th>Images</th> <th>Caption</th> <th>Action</th> </tr> </thead> <tbody> <?php if (mysqli_num_rows($result) > 0) { // output data of each row while ($row = mysqli_fetch_assoc($result)) { ?> <tr> <td><?= ++$serial ?></td> <td><img scr="./uploads/gallery/<?= $row['image'] ?>"/></td> <td><?= $row['caption'] ?></td> <td><a href="addgallery?picture_id=<?= $row[ 'id' ] ?>" class="btn btn-danger">Delete</a></td> </tr> <?php } } else { //echo '0 results'; } ?> </tbody> </table> </div> </div> </div> <?php include_once 'sections/footer.php'; ?>