Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpBB remote file upload

I want to be able to upload a remote file to my server through phpbb without having the file downloaded to my PC first. How can this be achieved?

I have some simple code that I have tested and it does the job, but where can I put it and what do I need to modify in 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);
}
?>

Or is it possible to tap into the remote avatar function in phpBB (ie. includes/functions_upload.php -> function remote_upload($upload_url))? I of course need the remote file to be sent through the usual phpBB functions to be inserted into the DB and all.

like image 367
Jizbo Jonez Avatar asked May 14 '13 11:05

Jizbo Jonez


1 Answers

open file includes/message_parser.php

find about line 1373

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

and replace with

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

open file includes/functions_posting.php

find about line 414

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

replace with

    $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

find

    <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>

add after

    <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>

Let me know if you would like me to create a mod for you to install with automod or if you need extra mime types with the remote_upload function

tested @ http:/www.damienkeitel.com

phpbbphpbb3

like image 180
Damien Keitel Avatar answered Oct 07 '22 17:10

Damien Keitel