setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die('Connection failed'); } require_once 'RateLimiter.php'; $rateLimiter = new RateLimiter($db); $rateLimiter->cleanup(); $ip = $_SERVER['REMOTE_ADDR']; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!$rateLimiter->isAllowed($ip)) { $error = 'Слишком много запросов'; } else { $message = trim($_POST['message'] ?? ''); $file = $_FILES['file'] ?? null; if ($message || ($file && $file['error'] === UPLOAD_ERR_OK)) { $postId = sprintf('%06d', mt_rand(1, 999999)); $fileName = null; $fileSize = null; $fileType = null; if ($file && $file['error'] === UPLOAD_ERR_OK) { $fileExt = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if (!in_array($fileExt, $config['allowed_types'])) { $error = 'Неподдерживаемый тип файла'; } elseif ($file['size'] > $config['max_file_size']) { $error = 'Файл слишком большой'; } else { $uploadDir = $config['upload_path']; if (!is_dir($uploadDir)) { mkdir($uploadDir, 0755, true); } $fileName = $postId . '.' . $fileExt; $filePath = $uploadDir . $fileName; if (move_uploaded_file($file['tmp_name'], $filePath)) { $fileSize = $file['size']; $fileType = $fileExt; } else { $error = 'Ошибка загрузки файла'; } } } if (empty($error)) { $stmt = $db->prepare(' INSERT INTO posts (post_id, message, file_name, file_size, file_type, ip_address) VALUES (?, ?, ?, ?, ?, ?) '); $stmt->execute([$postId, $message, $fileName, $fileSize, $fileType, $ip]); header('Location: board.php'); exit; } } else { $error = 'Введите сообщение или загрузите файл'; } } } if (isset($_GET['logout'])) { session_destroy(); header('Location: index.php'); exit; } try { $stmt = $db->query('SELECT * FROM posts ORDER BY created_at DESC LIMIT 100'); $posts = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { die('Database error'); } ?> mkach

mkach

File
( KB)