Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('dbConfig.php');
- $upload_dir = 'uploads/';
- if(isset($_GET['delete'])){
- $id = $_GET['delete'];
- //select old photo name from database
- $sql = "select photo from images where id = ".$id;
- $result = mysqli_query($conn, $sql);
- if(mysqli_num_rows($result) > 0){
- $row = mysqli_fetch_assoc($result);
- $photo = $row['photo'];
- unlink($upload_dir.$photo);
- //delete record from database
- $sql = "delete from images where id=".$id;
- if(mysqli_query($conn, $sql)){
- header('location:index.php');
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <style>
- .gallery picture {
- display: inline-block;
- margin: 5px;
- position: relative;
- overflow: hidden;
- width: 200px;
- height: 200px;
- }
- .gallery img {
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- width: 100%;
- }
- </style>
- <title>Uploadimage</title>
- <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-theme.min.css">
- </head>
- <body>
- <div class="navbar navbar-default">
- <div class="container">
- <div class="navbar-header">
- <h3 class="navbar-brand">PHP upload image</h3>
- </div>
- </div>
- </div>
- <div class="container">
- <div class="page-header">
- <h3>User List
- <a class="btn btn-default" href="add.php">
- <span class="glyphicon glyphicon-plus"></span> Add New
- </a>
- </h3>
- </div>
- <?php
- $sql = "select * from images";
- $result = mysqli_query($conn, $sql);
- if(mysqli_num_rows($result)){
- while($row = mysqli_fetch_assoc($result)){
- ?>
- <div class="gallery">
- <picture>
- <img src="<?php echo $upload_dir.$row['photo'] ?>" >
- </picture>
- </div>
- <a class="btn btn-info" href="edit.php?id=<?php echo $row['id'] ?>">
- <span class="glyphicon glyphicon-edit"></span>Edit
- </a>
- <a class="btn btn-danger" href="index.php?delete=<?php echo $row['id'] ?>" onclick="return confirm('Are you sure to delete this record?')">
- <span class="glyphicon glyphicon-remove-circle"></span>Delete
- </a>
- <?php
- }
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement