$driveInstance = \Bitrix\Disk\Driver::getInstance();$storage = $driveInstance->getStorageByUserId($id);$folder = $storage->getFolderForUploadedFiles();$arFiles = [];foreach ($_FILES as $arFile) {$data = ['NAME' => $arFile['name'], 'CREATED_BY' => $id];if ($fileModel = $folder->uploadFile($arFile, $data, array(), true)) {$arFiles[] = 'n' . $fileModel->getId();}}
$arFields = ["AUTHOR_NAME" => $name,"AUTHOR_ID" => $id,"POST_MESSAGE" => $message,"FORUM_ID" => $forum,"TOPIC_ID" => $topic,"NEW_TOPIC" => $new ? "Y" : "N"];if (!empty($arFiles)) {$arFields["UF_FORUM_MESSAGE_DOC"] = $arFiles;}$messageId = \CForumMessage::Add($arFields);