MAX_ATTACHMENT_COUNT) RequestUtils::triggerFormError(__("Too many attachments"), $formId); // check all attachments before saving one foreach ($attachments as $att) { if ($att["size"] > MAX_ATTACHMENT_SIZE) { RequestUtils::triggerFormError(__("Individual file size exceeded"), $formId); } } if (strlen($title) < 1 || strlen($title) > 255) { RequestUtils::triggerFormError(__("Title too short or too long!"), $formId); } if (strlen($message) < 1 || strlen($message) > 0x8000) { RequestUtils::triggerFormError(__("Message too short or too long!"), $formId); } $topic = new Topic(); $topic->createdBy = $currentUser->id; $topic->id = $db->generateId(); $topic->title = $title; $topic->creationDate = new DateTimeImmutable(); $topic->isLocked = false; $db->insert($topic); $item = new Post(); $item->id = $db->generateId(); $item->authorId = $currentUser->id; $item->topicId = $topic->id; $item->content = $message; $item->postDate = $topic->creationDate; $item->deleted = false; $item->edited = false; $db->insert($item); foreach ($attachments as $att) { [ "name" => $name, "type" => $type, "tmp_name" => $tmpName, ] = $att; $attachment = new Attachment(); $attachment->id = $db->generateId(); $attachment->name = $name; $attachment->mimeType = $type; $attachment->postId = $item->id; $attachment->contents = file_get_contents($tmpName); $db->insert($attachment); } header("Location: ?_action=viewtopic&topic=" . urlencode($topic->id));