D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
home
/
markniuj
/
.vscode-server
/
data
/
User
/
History
/
a11b0e8
/
Filename :
Dbdy.php
back
Copy
<?php include "../config.php"; ?> <!DOCTYPE html> <html> <head> <title>PDF Gallery</title> <link href="table.css" rel="stylesheet"> <meta content="width=device-width, initial-scale=1.0" name="viewport"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.0/css/all.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.4.1/font/bootstrap-icons.css" rel="stylesheet"> <style> .thumbnail { width: 50px; height: 50px; } table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: 8px; } th { background-color: #f2f2f2; } tr:nth-child(even) { background-color: #f2f2f2; } .edit-icon, .delete-icon { font-size: 16px; color: #007bff; text-decoration: none; margin: 0 5px; } </style> </head> <body> <h1>PDF Gallery</h1> <ul> <li> <a href="addpdf.php">Add PDF</a></li> <li> <a href="index.php">Main menu</a></li> </ul> <!-- Link to upload PDF --> <br> <!-- Table to display PDF information --> <table> <thead> <tr> <th>ID</th> <th>Book Name</th> <th>Title Cover</th> <th>PDF File</th> <th>PDF File Size</th> <th>Edit</th> <th>Delete</th> </tr> </thead> <tbody> <?php // Handle updating "hits" count when a user accesses the PDF file if (isset($_GET['file'])) { $pdfFile = $_GET['file']; $updateHitsQuery = "UPDATE pdf_books SET hits = hits + 1 WHERE pdf_filename = '$pdfFile'"; $conn->query($updateHitsQuery); } // SQL query to retrieve PDF information from the database $sql = "SELECT * FROM pdf_books ORDER BY upload_date DESC"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo "<tr>"; echo "<td>" . $row["id"] . "</td>"; echo "<td>" . $row["book_name"] . "</td>"; echo "<td><img class='thumbnail' src='uploads/pdf/title_covers/" . $row["title_cover"] . "' alt='Title Cover'></td>"; $fileSize = formatSizeUnits(filesize("pdf_files/" . $row["pdf_filename"])); echo "<td><a href='pdf_download.php?file=" . $row["pdf_filename"] . "'><center><i class='fa fa-download'></i></center></a></td>"; echo "<td>" . $fileSize . "</td>"; // Edit and Delete icons echo "<td><a href='edit_pdf.php?id=" . $row["id"] . "' class='edit-icon'><i class='bi bi-pencil'></i></a></td>"; echo "<td><a href='delete_pdf.php?id=" . $row["id"] . "' class='delete-icon'><i class='bi bi-trash'></i></a></td>"; echo "</tr>"; } } else { echo "<tr><td colspan='9'>No PDFs found in the database.</td></tr>"; } // Close the database connection $conn->close(); function formatSizeUnits($bytes) { // Function to format file size if ($bytes >= 1073741824) { $bytes = number_format($bytes / 1073741824, 2) . ' GB'; } elseif ($bytes >= 1048576) { $bytes = number_format($bytes / 1048576, 2) . ' MB'; } elseif ($bytes >= 1024) { $bytes = number_format($bytes / 1024, 2) . ' KB'; } elseif ($bytes > 1) { $bytes = $bytes . ' bytes'; } elseif ($bytes == 1) { $bytes = $bytes . ' byte'; } else { $bytes = '0 bytes'; } return $bytes; } ?> </tbody> </table> </body> </html>