通过phpscript向phpbb提交带有附件的帖子

通过phpscript向phpbb提交带有附件的帖子,php,phpbb,Php,Phpbb,我想用phpscript向我的phpbb论坛提交一篇帖子。 目前,我正在使用includes\functions\u posting.php中的submit\u post()函数来正确提交文章的文本和主题,但我也不知道如何提交附件。目前,我正在将文件保存到phpbb论坛的根文件夹中。 主题、文本和附件通过URL调用phpscript进行加密和传递。 我的代码: 我如何简单地向帖子提交附件?理想情况下使用submit_post()函数。 谢谢 <?php define('IN_P

我想用phpscript向我的phpbb论坛提交一篇帖子。 目前,我正在使用includes\functions\u posting.php中的submit\u post()函数来正确提交文章的文本和主题,但我也不知道如何提交附件。目前,我正在将文件保存到phpbb论坛的根文件夹中。 主题、文本和附件通过URL调用phpscript进行加密和传递。 我的代码:


我如何简单地向帖子提交附件?理想情况下使用submit_post()函数。 谢谢

    <?php
define('IN_PHPBB', true);
$phpbb_root_path = rootpath;
$phpEx = substr(strrchr(__FILE__, '.') , 1);

include ($phpbb_root_path . 'common.' . $phpEx);
include ($phpbb_root_path . 'includes/functions_posting.' . $phpEx);

$user_id = userid;
$forum_id = forumid;
$subject = hex2bin(request_var('subject', ""));
$text = hex2bin(request_var('text', ""));
$attachmentNumber = request_var('number', 0);
$attachmentNameArray = [];
$attachmentDataArray = [];
for ($i=1; $i <= $attachmentNumber; $i++){
    $attachmentNameArray[$i] = hex2bin(request_var('name'.$i, ""));
    $attachmentDataArray[$i] = hex2bin(request_var('attachment'.$i, ""));
    file_put_contents($phpbb_root_path . filestoragefolder. $attachmentNameArray[$i], $attachmentDataArray[$i]);
}

$user->session_create($user_id);
$auth->acl($user->data);
$user->setup();

$sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id=' . (int)$forum_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$forum_name = $row['forum_name'];
//Submit the new post
$poll = $uid = $bitfield = $flags = '';
generate_text_for_storage($text, $uid, $bitfield, $flags, true, true, true);


$data = array( 
    'forum_id'      => $forum_id,
    'topic_id'       => 0,
    'icon_id'       => false,
    'enable_bbcode'     => true,
    'enable_smilies'    => true,
    'enable_urls'       => true,
    'enable_sig'        => true,
    'message'       => $text,
    'message_md5'   => md5($text),
    'bbcode_bitfield'   => $bitfield,
    'bbcode_uid'        => $uid,
    'post_edit_locked'  => 0,
    'topic_title'       => $subject,
    'notify_set'        => false,
    'notify'            => false,
    'post_time'         => 0,
    'forum_name'        => $forum_name,
    'enable_indexing'   => true,
    'force_approved_state'    => true,
    'force_visibility'            => true,
);

$result = submit_post('post', $subject, '', POST_NORMAL, $poll, $data);
if ($result===FALSE){
    echo "Error sending post";
}
else{
    echo "Post sent successfully, URL is: $result";
}

$user->session_kill(false);
?>