setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die('Connection failed'); } require_once 'RateLimiter.php'; require_once 'AnonymousID.php'; $rateLimiter = new RateLimiter($db); $rateLimiter->cleanup(); $ip = $_SERVER['REMOTE_ADDR']; $anonymousID = new AnonymousID($db, $ip, $boardId); try { $db->exec('SET NAMES utf8'); $stmt = $db->prepare('SELECT * FROM boards WHERE board_id = ?'); $stmt->execute([$boardId]); $board = $stmt->fetch(PDO::FETCH_ASSOC); if (!$board) { header('Location: index.php'); exit; } } catch (PDOException $e) { die('Database error'); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!$rateLimiter->isAllowed($ip)) { $error = 'Слишком много запросов'; } else { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $message = trim($_POST['message'] ?? ''); $file = $_FILES['file'] ?? null; if ($title && ($description || $message || ($file && $file['error'] === UPLOAD_ERR_OK))) { $threadId = sprintf('%06d', mt_rand(1, 999999)); $postId = sprintf('%06d', mt_rand(1, 999999)); $anonymousId = $anonymousID->getIDForThread(); $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 = $threadId . '.' . $fileExt; $filePath = $uploadDir . $fileName; if (move_uploaded_file($file['tmp_name'], $filePath)) { $fileSize = $file['size']; $fileType = $fileExt; } else { $error = 'Ошибка загрузки файла: ' . error_get_last()['message']; } } } if (empty($error)) { $stmt = $db->prepare(' INSERT INTO threads (thread_id, board_id, title, description, file_name, file_size, file_type, ip_address, anonymous_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) '); $stmt->execute([$threadId, $boardId, $title, $description, $fileName, $fileSize, $fileType, $ip, $anonymousId]); $stmt = $db->prepare(' INSERT INTO posts (post_id, thread_id, board_id, message, file_name, file_size, file_type, ip_address, anonymous_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) '); $stmt->execute([$postId, $threadId, $boardId, $message, $fileName, $fileSize, $fileType, $ip, $anonymousId]); header('Location: board.php?board=' . urlencode($boardId) . '&thread=' . urlencode($threadId)); exit; } } else { $error = 'Введите название треда и хотя бы описание, сообщение или файл'; } } } ?> mkach - Создать тред в /<?= htmlspecialchars($boardId) ?>/

mkach - Создать тред в //

Создать новый тред

Отмена

Поддерживаемые теги Markdown:

  • **жирный** - жирный текст
  • *курсив* - курсив
  • _подчеркнутый_ - подчеркнутый
  • ~~зачеркнутый~~ - зачеркнутый
  • `код` - код
  • >>123456 - ссылка на пост
  • [текст](url) - ссылка
  • * элемент - список