File manager - Edit - /home/familylifersmpc/htdocs/www.familylifersmpc.com/view_posts.php
Back
<?php error_reporting(0); include('editor-includes/web-config.php'); $conn = new mysqli($host, $user, $pass, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Delete single image if requested if (isset($_GET['delete'])) { $fileToDelete = $_GET['delete']; if (file_exists($fileToDelete)) { // Fixed: Removed the "filename:" part unlink($fileToDelete); echo "<div class='alert alert-success text-center'>Image deleted successfully!</div>"; } else { echo "<div class='alert alert-danger text-center'>Image not found!</div>"; } } // Delete entire post if requested if (isset($_GET['delete_post'])) { $folderName = $conn->real_escape_string($_GET['delete_post']); $folderPath = "UPLOADS/" . $folderName; // Delete folder and its files if (is_dir($folderPath)) { $files = array_diff(scandir($folderPath), ['.', '..']); foreach ($files as $file) { unlink($folderPath . '/' . $file); } rmdir($folderPath); } // Delete post from database by FolderName $conn->query("DELETE FROM postingtbl WHERE FolderName='$folderName'"); echo "<div class='alert alert-success text-center'>Post deleted successfully!</div>"; } // --- Pagination Setup --- $limit = 6; // posts per page $page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1; $offset = ($page - 1) * $limit; // Get total number of posts $totalResult = $conn->query("SELECT COUNT(*) AS total FROM postingtbl"); $totalRow = $totalResult->fetch_assoc(); $totalPosts = $totalRow['total']; $totalPages = ceil($totalPosts / $limit); // Fetch posts for current page $result = $conn->query("SELECT * FROM postingtbl ORDER BY ID DESC LIMIT $limit OFFSET $offset"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>View Posts</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <style> body { background: #f8f9fa; } .post-card { border-radius: 15px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); margin-bottom: 30px; } .img-thumb { width: 120px; height: 100px; object-fit: cover; border-radius: 10px; margin: 5px; } .delete-link { color: #dc3545; font-size: 13px; display: block; text-align: center; margin-top: 3px; text-decoration: none; } .gallery { display: flex; flex-wrap: wrap; } .gallery-item { text-align: center; margin: 5px; } .btn-new { margin: 20px 0; border-radius: 25px; } .btn-delete-post { margin-bottom: 10px; } </style> </head> <body> <div class="container"> <h2 class="text-center my-4">All Posts</h2> <div class="text-center mb-3"> <a href="edashboard.php" class="btn btn-success btn-new">+ Create New Post</a> </div> <?php while ($row = $result->fetch_assoc()): ?> <div class="card post-card p-3"> <h4><?php echo htmlspecialchars($row['Title']); ?></h4> <p><?php echo nl2br(htmlspecialchars($row['Description'])); ?></p> <!-- Delete Post Button --> <div class="text-end"> <a href="?delete_post=<?php echo urlencode($row['FolderName']); ?>&page=<?php echo $page; ?>" class="btn btn-danger btn-sm btn-delete-post" onclick="return confirm('Are you sure you want to delete this entire post?')"> Delete Post </a> </div> <!-- Image Gallery --> <div class="gallery"> <?php $folder = "UPLOADS/" . $row['FolderName']; if (is_dir($folder)) { $files = scandir($folder); foreach ($files as $file) { if ($file != "." && $file != "..") { $filePath = $folder . "/" . $file; $encodedPath = urlencode($filePath); echo "<div class='gallery-item'> <img src='$filePath' class='img-thumb'> <a class='delete-link' href='?delete=$encodedPath&page=$page' onclick=\"return confirm('Delete this image?')\">Delete</a> </div>"; } } } ?> </div> </div> <?php endwhile; ?> <!-- Pagination --> <nav aria-label="Page navigation example"> <ul class="pagination justify-content-center mt-4"> <?php if ($page > 1): ?> <li class="page-item"> <a class="page-link" href="?page=<?php echo $page - 1; ?>">Previous</a> </li> <?php endif; ?> <?php for ($i = 1; $i <= $totalPages; $i++): ?> <li class="page-item <?php if ($i == $page) echo 'active'; ?>"> <a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a> </li> <?php endfor; ?> <?php if ($page < $totalPages): ?> <li class="page-item"> <a class="page-link" href="?page=<?php echo $page + 1; ?>">Next</a> </li> <?php endif; ?> </ul> </nav> </div> </body> </html> <?php $conn->close(); ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.03 |
proxy
|
phpinfo
|
Settings