0byt3m1n1
Path:
C:
/
Users
/
Administrator
/
Desktop
/
CWRDM Backup
/
WaterCat
/
[
Home
]
File: list_images.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>List of Images</title> <link rel="stylesheet" type="text/css" href="styles.css"> <link rel="stylesheet" type="text/css" href="nav.css"> <style> body { font-family: Arial, sans-serif; background-color: #f5f5f5; margin: 0; padding: 0; } .container { max-width: 800px; margin: 20px auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); } h1 { text-align: center; margin-bottom: 20px; } table { width: 100%; border-collapse: collapse; } th, td { padding: 10px; border: 1px solid #ddd; text-align: left; } th { background-color: #f2f2f2; } td img { max-width: 500px; height: auto; display: block; margin: 0 auto; } .delete-link { color: black; text-decoration: none; font-weight: bold; padding: 5px 10px; border: 1px solid red; border-radius: 3px; background-color:#ed5a6c; } .delete-link:hover { background-color: #ffcccc; border-color: #ff6666; } .button { background-color: #4CAF50; /* Green */ border: none; color: white; padding: 10px 30px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; } </style> </head> <body class="bg-white" style="background-image: url('assets/images/slider/s1.jpg');"> <div class="topnav"> <a class="active" href="indexnew.php">Home</a> <a href="newsnew.php">News</a> <a href="contact.php">Contact</a> <a href="about.html">About</a> </div> <div class="container"> <h1>Gallery Images</h1> <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "watercat"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Function to delete image from both database and folder function deleteImage($conn, $image_id, $image_name) { // Delete from database $delete_sql = "DELETE FROM images WHERE id = $image_id"; if ($conn->query($delete_sql) === TRUE) { // Delete from folder $folder = "gallery/" . $image_name; if (unlink($folder)) { echo "<script>alert('Image deleted successfully.');</script>"; echo "<script>window.location.href = 'list_images.php';</script>"; // Redirect to refresh the list } else { echo "<script>alert('Failed to delete image from folder.');</script>"; } } else { echo "<script>alert('Failed to delete image from database.');</script>"; } } // Fetch images from database $sql = "SELECT id, image_name, image_description FROM images"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table border='1'> <tr> <th>ID</th> <th>Image</th> <th>Description</th> <th>Action</th> </tr>"; // Output data of each row while($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td><img src='gallery/" . $row["image_name"] . "' height='100'></td>"; echo "<td>" . $row["image_description"] . "</td>"; echo "<td><a href='?delete=" . $row["id"] . "&filename=" . $row["image_name"] . "' class='delete-link'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } else { echo "0 results"; } // Handle image deletion if (isset($_GET['delete'])) { $image_id = $_GET['delete']; $image_name = $_GET['filename']; deleteImage($conn, $image_id, $image_name); } $conn->close(); ?>