phpBB 远程文件上传

8

我希望能够通过phpbb将远程文件上传到我的服务器,而不必先将文件下载到我的电脑上。如何实现这一点?

我有一些简单的代码,我已经测试过,它可以完成任务,但我应该将它放在哪里,还需要修改phpBB的什么内容?

<form method="post">
    <input name="url" size="50"/>
    <input name="submit" type="submit"/>
</form>

<?php
// maximum execution time in seconds
set_time_limit(24 * 60 * 60);

if (!isset($_POST['submit'])) die();

// folder to save downloaded files to. must end with slash
$destination_folder = 'mydownloads/';

$url = $_POST['url'];
$newfname = $destination_folder . basename($url);

//Open remote file
$file = fopen($url, "rb");
if ($file) {
    //Write to local file
    $newf = fopen($newfname, "wb");
    if ($newf) {
        while (!feof($file)) {
            fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
        }
    }
}

if ($file) {
    fclose($file);
}

if ($newf) {
    fclose($newf);
}
?>

是否可以在phpBB中利用远程头像功能(即includes/functions_upload.php->function remote_upload($upload_url))?当然,我需要通过常规的phpBB函数发送远程文件,以便将其插入到数据库中。


你使用的是哪个版本? - Abadis
最新版本 - 3.0.11 - Jizbo Jonez
1
创建 includes/functions_upload.php 的备份,然后打开原始文件,在必要的位置放置您的代码,然后按照 PHPBB 上传文件的过程(插入到数据库中,检查恶意文件)进行操作并尝试它。 - Jake Ball
你是否需要使用头像或者是在帖子中插入文件,需要进行进一步的确认。 - Damien Keitel
我正在尝试通过phpBB3的常规“上传附件”表单插入远程文件。 - Jizbo Jonez
1个回答

4

打开文件 includes/message_parser.php

找到大约在第1373行附近的位置

    $upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false;

并替换为

    $upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : (!empty($_POST['urlupload'])) ? true : false;

打开文件 includes/functions_posting.php

找到大约在第 414 行的位置

    $file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);

替换为

    $file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : (!empty($_POST['urlupload'])) ? $upload->remote_upload($_POST['urlupload']) : $upload->form_upload($form_name);

open styles/your_style/templates/posting_attach_body.html
查找
    <dl>
    <dt><label for="fileupload">{L_FILENAME}:</label></dt>
    <dd>
        <input type="file" name="fileupload" id="fileupload" maxlength="{FILESIZE}" value="" class="inputbox autowidth" /> 
        <input type="submit" name="add_file" value="{L_ADD_FILE}" class="button2" onclick="upload = true;" />
    </dd>
</dl>

添加在后面

    <dl>
    <dt><label for="urlupload">Remote File:</label></dt>
    <dd>
        <input type="url" name="urlupload" id="urlupload" maxlength="{FILESIZE}" value="" class="inputbox autowidth" /> 
        <input type="submit" name="add_file" value="{L_ADD_FILE}" class="button2" onclick="upload = true;" />
    </dd>
</dl>

让我知道你是否需要我为你创建一个使用automod安装的mod,或者如果你需要在remote_upload函数中使用额外的mime类型。
http:/www.damienkeitel.com上进行了测试。

2
自动审核程序安装在此处 -> https://www.phpbb.com/community/viewtopic.php?f=70&t=2184331&p=13312954 - Damien Keitel
感谢您的模块,这比我想象中的要好得多。我已经尝试了它,但是遇到了一个问题,当我尝试上传时,会出现“您指定的URL无效”的错误提示。我知道这个URL是正确的。 - Jizbo Jonez
你是否进入了扩展功能并允许了相应的扩展?在“发布/管理扩展组”中,然后点击任何一个齿轮以启用不同的文件类型/扩展名。 - Damien Keitel
请问您能提供一下您正在测试的链接吗? - Damien Keitel
@DamienKeitel 先生,我正在制作一个类似的项目,其中我需要将我的 phpBB 论坛的整个上传机制从上传文件到我的服务器改为上传到我的 Google Drive。我正在使用 Google Drive API 来实现它,并且我能够替换 post_attach_body 模板文件中的默认附件发布机制,但我不知道如何将上传文件的返回 URL 存储到帖子中。您能帮忙吗? - Harshit Laddha
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接