Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php
  2. require_once('dbConfig.php');
  3. $upload_dir = 'uploads/';
  4. if(isset($_GET['delete'])){
  5. $id = $_GET['delete'];
  6.  
  7. //select old photo name from database
  8. $sql = "select photo from images where id = ".$id;
  9. $result = mysqli_query($conn, $sql);
  10. if(mysqli_num_rows($result) > 0){
  11. $row = mysqli_fetch_assoc($result);
  12. $photo = $row['photo'];
  13. unlink($upload_dir.$photo);
  14. //delete record from database
  15. $sql = "delete from images where id=".$id;
  16. if(mysqli_query($conn, $sql)){
  17. header('location:index.php');
  18. }
  19. }
  20. }
  21. ?>
  22. <!DOCTYPE html>
  23. <html>
  24. <head>
  25. <style>
  26. .gallery picture {
  27. display: inline-block;
  28. margin: 5px;
  29. position: relative;
  30. overflow: hidden;
  31. width: 200px;
  32. height: 200px;
  33. }
  34.  
  35. .gallery img {
  36. position: absolute;
  37. top: 50%;
  38. transform: translateY(-50%);
  39. width: 100%;
  40. }
  41. </style>
  42. <title>Uploadimage</title>
  43. <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css">
  44. <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-theme.min.css">
  45. </head>
  46. <body>
  47.  
  48. <div class="navbar navbar-default">
  49. <div class="container">
  50. <div class="navbar-header">
  51. <h3 class="navbar-brand">PHP upload image</h3>
  52. </div>
  53. </div>
  54. </div>
  55. <div class="container">
  56. <div class="page-header">
  57. <h3>User List
  58. <a class="btn btn-default" href="add.php">
  59. <span class="glyphicon glyphicon-plus"></span> &nbsp;Add New
  60. </a>
  61. </h3>
  62. </div>
  63. <?php
  64. $sql = "select * from images";
  65. $result = mysqli_query($conn, $sql);
  66. if(mysqli_num_rows($result)){
  67. while($row = mysqli_fetch_assoc($result)){
  68. ?>
  69. <div class="gallery">
  70.  
  71. <picture>
  72. <img src="<?php echo $upload_dir.$row['photo'] ?>" >
  73.  
  74. </picture>
  75. </div>
  76.  
  77.  
  78. <a class="btn btn-info" href="edit.php?id=<?php echo $row['id'] ?>">
  79. <span class="glyphicon glyphicon-edit"></span>Edit
  80. </a>
  81. <a class="btn btn-danger" href="index.php?delete=<?php echo $row['id'] ?>" onclick="return confirm('Are you sure to delete this record?')">
  82. <span class="glyphicon glyphicon-remove-circle"></span>Delete
  83. </a>
  84.  
  85. <?php
  86. }
  87. }
  88. ?>
  89.  
  90. </div>
  91.  
  92. </body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement