D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
public_html
/
encoadminders
/
Filename :
gallery.php
back
Copy
<?php session_start(); include 'config.php'; // Check if the user is logged in if (!isset($_SESSION['admin_name'])) { echo '<script>window.location.href = "login.php";</script>'; exit; } // Check if 'id' is passed to delete a gallery item if (isset($_GET['id'])) { $gallery_id = $_GET['id']; // Fetch the image file name associated with the gallery item $query = "SELECT image FROM gallery WHERE gallery_id = '$gallery_id'"; $result = mysqli_query($conn, $query); if ($result && mysqli_num_rows($result) > 0) { $row = mysqli_fetch_assoc($result); $image_name = $row['image']; // Delete the image file from the server $image_path = 'uploads/gallery/' . $image_name; if (file_exists($image_path)) { unlink($image_path); } // Delete the gallery record from the database $delete_query = "DELETE FROM gallery WHERE gallery_id = '$gallery_id'"; if (mysqli_query($conn, $delete_query)) { $_SESSION['message'] = 'Gallery item deleted successfully.'; } else { $_SESSION['message'] = 'Failed to delete gallery item from the database.'; } } else { $_SESSION['message'] = 'Gallery item not found.'; } header('Location: gallery.php'); exit; } // Fetch all gallery items to display $query = "SELECT * FROM gallery ORDER BY gallery_id DESC"; $result = mysqli_query($conn, $query); if (!$result) { die("Query failed: " . mysqli_error($conn)); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Gallery</title> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet"> <?php include 'style.php' ?> <style> /* General Reset */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Poppins', sans-serif; line-height: 1.6; background-color: #f9f9f9; color: #333; } /* Sidebar Styling */ /* Gallery Container */ .gallery-container { max-width: 1200px; margin: 0 auto; background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .gallery-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .gallery-header h1 { font-size: 24px; color: #2c3e50; } .btn-add { padding: 10px 20px; background-color: #27ae60; color: #fff; border: none; border-radius: 5px; text-decoration: none; font-weight: 600; transition: background-color 0.3s ease; } .btn-add:hover { background-color: #219150; } /* Table Styling */ table { width: 100%; border-collapse: collapse; margin: 20px 0; font-size: 16px; } thead { background-color: #34495e; color: #fff; } thead th { text-align: left; padding: 10px; } tbody tr { border-bottom: 1px solid #ddd; } tbody tr:hover { background-color: #f1f1f1; } tbody td { padding: 10px; vertical-align: middle; } .gallery-image { max-width: 100px; height: auto; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .action-buttons a { text-decoration: none; padding: 8px 12px; margin-right: 5px; font-size: 14px; border-radius: 5px; transition: background-color 0.3s ease; } .btn-edit { background-color: #3498db; color: #fff; } .btn-edit:hover { background-color: #2980b9; } .btn-delete { background-color: #e74c3c; color: #fff; } .btn-delete:hover { background-color: #c0392b; } /* Alerts */ .alert { padding: 15px; background-color: #27ae60; color: #fff; border-radius: 5px; margin-bottom: 20px; font-size: 14px; text-align: center; } .alert.error { background-color: #e74c3c; } /* Footer Styling */ footer { text-align: center; margin-top: 20px; font-size: 14px; color: #7f8c8d; } footer a { color: #3498db; text-decoration: none; } /* Responsive Design */ @media (max-width: 768px) { .gallery-header { flex-direction: column; align-items: flex-start; } .btn-add { margin-top: 10px; align-self: stretch; text-align: center; } table { font-size: 14px; } .gallery-image { max-width: 80px; } .action-buttons a { font-size: 12px; padding: 5px 10px; } } </style> </head> <body> <?php include('sidebar.php') ?> <div class="home-section"> <div class="gallery-container"> <div class="gallery-header"> <h1>Gallery</h1> <a href="add_gallery.php" class="btn-add">Add New Image</a> </div> <!-- Display success or error message --> <?php if (isset($_SESSION['message'])): ?> <div class="alert"> <?php echo $_SESSION['message']; unset($_SESSION['message']); ?> </div> <?php endif; ?> <table> <thead> <tr> <th>ID</th> <th>Image</th> <th>Title</th> <th>Category</th> <th>Actions</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_assoc($result)) : ?> <tr> <td><?php echo htmlspecialchars($row['gallery_id']); ?></td> <td> <img src="uploads/gallery/<?php echo htmlspecialchars($row['image']); ?>" alt="Gallery Image" class="gallery-image"> </td> <td><?php echo htmlspecialchars($row['title']); ?></td> <td><?php echo htmlspecialchars($row['category']); ?></td> <td class="action-buttons"> <a href="edit_gallery.php?id=<?php echo $row['gallery_id']; ?>" class="btn-edit">Edit</a> <a href="?id=<?php echo $row['gallery_id']; ?>" class="btn-delete" onclick="return confirm('Are you sure you want to delete this item?');">Delete</a> </td> </tr> <?php endwhile; ?> </tbody> </table> </div> <?php include('footer.php') ?> </div> </body> </html>