Untitled

Anonymous
html
10/19/2026 12:01 PM
4.9 KB
3
Indexable
<!DOCTYPE html>
<html lang="vi">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Danh Sách Tệp Tin - Download</title>
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f4f6f9; color: #333; padding: 40px 20px; }
        .container { max-width: 700px; margin: 0 auto; background: #fff; padding: 40px; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
        h2 { color: #2c3e50; margin-bottom: 20px; font-size: 18pt; text-align: center; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; }
        th { background-color: #f8fafc; color: #2c3e50; font-weight: bold; }
        .download-link { color: #2ecc71; text-decoration: none; font-weight: bold; }
        .download-link:hover { text-decoration: underline; color: #27ae60; }
        .back-link { display: inline-block; margin-top: 20px; color: #7f8c8d; text-decoration: none; font-size: 10pt; }
        .back-link:hover { color: #333; }
        .no-file { text-align: center; color: #999; padding: 20px; }
    </style>
</head>
<body>
    <div class="container">
        <h2>Danh Sách Tài Nguyên Tải Về</h2>
        <table>
            <thead>
                <tr>
                    <th>Tên Tệp Tin</th>
                    <th>Kích Thước</th>
                    <th>Hành Động</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $dir = "uploads/";

                // Kiểm tra nếu thư mục tồn tại
                if (is_dir($dir)) {
                    // Đọc toàn bộ file trong thư mục, loại bỏ dấu chấm "." và ".."
                    $files = array_diff(scandir($dir), array('.', '..'));

                    if (count($files) > 0) {
                        foreach ($files as $file) {
                            $file_path = $dir . $file;
                            // Tính kích thước file (đổi sang KB hoặc MB cho dễ nhìn)
                            $size_bytes = filesize($file_path);
                            if ($size_bytes >= 1048576) {
                                $file_size = round($size_bytes / 1048576, 2) . ' MB';
                            } else {
                                $file_size = round($size_bytes / 1024, 2) . ' KB';
                            }

                            // In ra từng dòng tương ứng với mỗi file tìm thấy
                            echo "<tr>";
                            echo "<td>" . htmlspecialchars($file) . "</td>";
                            echo "<td>" . $file_size . "</td>";
                            // Link trực tiếp tới vị trí của file để trình duyệt tải xuống
                            echo "<td><a href='" . $file_path . "' class='download-link' download>Tải về</a></td>";
                            echo "</tr>";
                        }
                    } else {
                        echo "<tr><td colspan='3' class='no-file'>Thư mục trống. Chưa có tệp tin nào được tải lên.</td></tr>";
                    }
                } else {
                    echo "<tr><td colspan='3' class='no-file'>Hệ thống lỗi: Không tìm thấy thư mục lưu trữ.</td></tr>";
                }
                ?>
            </tbody>
        </table>
        <a href="index.html" class="back-link">&larr; Quay lại trang chủ</a>
    </div>
</body>
</html>
Editor is loading...
Leave a Comment