<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Photos</title>
    <style>
        body { font-family: Arial, sans-serif; background-color: #f4f5f7; padding: 20px; margin: 0; }
        .gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; }
        .gallery-item { background: #fff; padding: 10px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); text-align: center; }
        .gallery-item img { width: 100%; height: 150px; object-fit: cover; border-radius: 5px; }
        .file-name { display: block; margin-top: 10px; font-size: 14px; color: #333; word-break: break-all; }
    </style>
</head>
<body>
    <div class="gallery-grid">
        <?php
        $dir = 'media/';  // destonation
        $extensions = ['jpg', 'jpeg', 'png', 'gif'];
        
        if (is_dir($dir)) {
            $files = scandir($dir);
            foreach ($files as $file) {
                $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                if (in_array($ext, $extensions)) {
                    $filePath = $dir . $file;
                    echo '<div class="gallery-item">';
                    echo '<a href="' . $filePath . '" target="_blank"><img src="' . $filePath . '" alt="' . $file . '"></a>';
                    echo '<span class="file-name">' . $file . '</span>';
                    echo '</div>';
                }
            }
        } else {
            echo '<p>Dir not exists</p>';
        }
        ?>
    </div>
</body>
</html>
