Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Настройки
- $uploadDir = 'uploads/';
- $allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'];
- $maxFileSize = 5 * 1024 * 1024; // 5 MB
- // Обработка загрузки файла
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
- $file = $_FILES['image'];
- $fileName = $file['name'];
- $fileTmpPath = $file['tmp_name'];
- $fileSize = $file['size'];
- $fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
- if (in_array($fileExtension, $allowedExtensions) && $fileSize <= $maxFileSize) {
- $newFileName = uniqid() . '.' . $fileExtension;
- $destinationPath = $uploadDir . $newFileName;
- move_uploaded_file($fileTmpPath, $destinationPath);
- }
- }
- // Получение списка загруженных файлов
- $files = glob($uploadDir . '*');
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Простая имиджборда</title>
- </head>
- <body>
- <h1>Простая имиджборда</h1>
- <form action="" method="post" enctype="multipart/form-data">
- <input type="file" name="image" accept="image/*" required>
- <button type="submit">Загрузить</button>
- </form>
- <div>
- <?php foreach ($files as $file): ?>
- <img src="<?= $file ?>" alt="Загруженное изображение" style="max-width: 200px; max-height: 200px;">
- <?php endforeach; ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment