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.

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


Need Your Help

Java: Parsing for empty spaces using Pattern and Matcher

java regex pattern-matching

I have a form with an edit box for entering valid email-address. I dont want the user to enter spaces in the email id edit box. As soon a text is entered i call two funcs

ZendFramework integration with other frameworks

php javascript css zend-framework frameworks

I want to make this question a guide for those interested in ZendFramework integration with other libraries/frameworks. Searching over StackOverflow doesn't give a broad view on the subject.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.