phpBB remote file upload
Asked Answered
C

1

8

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.

Cohleen answered 14/5, 2013 at 11:37 Comment(5)
which version are you using?Hoch
the latest version - 3.0.11Cohleen
Create a back-up of includes/functions_upload.php and then open up the original, place your code where necessary and then follow the process that PHPBB uploads files (inserting into db, checking for malicious files) and try it out.Siclari
Trying to figure out if you need to use an avatar or your inserting a file into a post.Utmost
I am trying to insert a remote file through the normal 'upload attachments' form of phpBB3Cohleen
U
4

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

Utmost answered 23/5, 2013 at 14:34 Comment(8)
Automod install here -> phpbb.com/community/…Utmost
Thanks for the mod, that's more than I could hope for. I have tried it out but am having a problem, I get => The URL you specified is invalid. when trying to upload. I know this url is fine.Cohleen
Have you gone into extensions and allowed the extensions? posting/mange extensions group and then click any of the cog wheels to enable different file types/extensions to be usedUtmost
yes the extension is allowed, I can upload the same type through the normal phpBB attachment upload. I'll have a look in the morning and see what is going on. CheersCohleen
Can I get the link your trying to use for testing pleaseUtmost
I found a few problems with the forum and am installing a fresh version to test this mod out. I will get back to you shortly. I have given you the 50 bounty for your efforts. ThanksCohleen
Cheers, if you need help. Just ask :)Utmost
@DamienKeitel sir i am making a similar project where I have to replace this entire upload mechanism of my phpBB forum from uploading files at my server to my google drive instead. I am using google drive api to achieve it and I am able to replace the default attachment posting mechanism from the post_attach_body template file but I dont know how to store the returned url of uploaded file to the post. Can you please help.Saddlery

© 2022 - 2024 — McMap. All rights reserved.