vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Beta Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=34)
-   -   Attachment Upload by URL (https://vborg.vbsupport.ru/showthread.php?t=80833)

akanevsky 04-30-2005 10:00 PM

Attachment Upload by URL
 
/*================================================= =====================*\
|| Attachment Upload by URL
|| Author : Psionic Vision
|| Works on : vBulletin 3.0.7 Only
\*================================================ ======================*/

There have been some requests for attachment upload by URL option... So here it is - my atttempt to create something like this. I am not sure that the way I did it is completely valid, but it does work. That is why I put it in beta releases. The code is fairly short, so it will not take more than one minute to install or remove it.

What this does is, it allows a user to upload an attachment from an URL rather than directly from user's computer. Sometime it is very useful.

Please test it out and comment and/or criticize. Thanks.

Edit: A fix was posted, please see this post:
https://vborg.vbsupport.ru/showpost....7&postcount=14
This fix is included into the new manual.

nexialys 05-01-2005 04:58 PM

a description of the tool please.. .title is not making any credit to your work.. ;)

jugo 05-01-2005 06:03 PM

I believe it allows you to attach a file from a url instead of uploading it.

akanevsky 05-01-2005 06:04 PM

jugo,
Exactly.

jugo 05-01-2005 06:17 PM

In That Case:

/me installed faster than a fat chick heads to the buffet.

Thanks Bro!!!

KTBleeding 05-01-2005 06:18 PM

Does this attach images using the [img] bbcode? Or does it add a new line to the attachment part with the option of a URL?

akanevsky 05-01-2005 06:27 PM

Yes, it adds a field for URL input next to the field for file input :)

Quote:

Thanks Bro!!!
:)

sabret00the 05-01-2005 06:35 PM

very sweet mod, should've been part of the product ages ago.

Reminder 05-01-2005 07:31 PM

Not working. Error "Please select a file to attach using the "Browse..." button."

akanevsky 05-01-2005 08:12 PM

Then you did not install it correctly. What is your vB version?

Zachery 05-01-2005 08:18 PM

Quote:

Originally Posted by reminder
Not working. Error "Please select a file to attach using the "Browse..." button."

Please do not report a post if its not working for you. You should contact the author or uninstall the hack

Reminder 05-01-2005 08:39 PM

Quote:

Originally Posted by Zachery
Please do not report a post if its not working for you. You should contact the author or uninstall the hack

Oppps. Sory. Ok. :)

Lionel 05-01-2005 09:08 PM

Your problem is in the javascript in template that checks for a value in upload field.

akanevsky 05-01-2005 09:25 PM

Sorry, I forgot to include that into the instructions. Will update them in a minute.

The fix is as follows:

In template 'newattachment', find:

Code:

if (elm.type == 'file')
and replace with:

Code:

if ((elm.type == 'file') || (elm.type == 'text'))

AN-net 05-01-2005 10:50 PM

from the looks of it this hack requires curl which is not a standard library, you should mention this in the first post;)

pretty cool though, i may look into it;)

Trigunflame 05-01-2005 11:17 PM

Quote:

Originally Posted by AN-net
from the looks of it this hack requires curl which is not a standard library, you should mention this in the first post;)

pretty cool though, i may look into it;)

Yes he is using curl.
This can be done much easier with fopen.

I have not Installed this hack, or tested my file change.. It should work though.

Replace the Code he gives in the install file with this.

PHP Code:

        if (is_array($_POST['attachmenturl']))
        {
            foreach (
$_POST['attachmenturl'] AS $key => $url)
            {
                
// attempt to fetch the filename from the url
                
preg_match('/\/([A-z0-9]*)([\.]{1})([A-z0-9]{2,6})$/si'$url$matches);
                
$filename['original'] = str_replace("/"""$matches[0]);

                
// did we retrieve a valid filename?
                
$validurl iif(!empty($url) AND !empty($filename['original']), truefalse);

                
/*
                 * FOPEN Modification By Trigunflame
                 */
                // valid url
                
if ($validurl)
                {
                    
// init
                    
$data '';

                    
// cancel the file that might have been uploaded
                    
unset($_FILES["attachment{$key}"]);

                    
// attempt opening of remote file
                    
if ($fileOpen = @fopen($url"rb"))
                    {
                        while (!
feof($fileOpen))
                        {
                            
$data = @fread($fileOpen4096);
                        }
                        @
fclose($fileOpen);
                    }

                    
// empty
                    
if (empty($data))
                    {
                        
$error construct_phrase($vbphrase['error_cannot_retrieve_url'], $url);
                        
$errors[] = array(
                            
'filename' => htmlspecialchars_uni($url),
                            
'error' => $error
                        
);
                    }

                    
// save file
                    
else
                    {
                        
$tmp_name 'vbupload' substr(TIMENOW, -4);
                        
$filesize strlen($data);
    
                        
// write file to temporary directory...
                        
if ($vboptions['safeupload'])
                        {
                            
// ... in safe mode
                            
$filename['temp'] = $vboptions['tmppath'] . "/$tmp_name";
                            
$filenum = @fopen($filename['temp'], 'wb');
                            @
fwrite($filenum$data);
                            @
fclose($filenum);
                        }
                        else
                        {
                            
// ... in normal mode
                            
$filename['temp'] = tempnam(ini_get('upload_tmp_dir'), 'vbupload');
                            
$fp = @fopen($filename['temp'], 'wb');
                            @
fwrite($fp$data);
                            @
fclose($fp);
                        }

                        
$_FILES["attachment$key"]['name'] = $filename['original'];
                        
$_FILES["attachment$key"]['type'] = '';
                        
$_FILES["attachment$key"]['size'] = $filesize;
                        
$_FILES["attachment$key"]['tmp_name'] = $filename['temp'];
                        
$_FILES["attachment$key"]['error'] = 0;
                        
$_FILES["attachment$key"]['url_upload_by_curl'] = 1;
                    }
                }
            }
        } 


Allan 05-02-2005 12:18 AM

screenshot please, just for looking ?

Reminder 05-02-2005 06:20 AM

Quote:

Originally Posted by Dark Visor
Then you did not install it correctly. What is your vB version?

Vbulletin Version 3.0.7

Boofo 05-03-2005 02:59 PM

Quote:

Originally Posted by Trigunflame
Yes he is using curl.
This can be done much easier with fopen.

I have not Installed this hack, or tested my file change.. It should work though.

Replace the Code he gives in the install file with this.

PHP Code:

        if (is_array($_POST['attachmenturl']))
        {
            foreach (
$_POST['attachmenturl'] AS $key => $url)
            {
                
// attempt to fetch the filename from the url
                
preg_match('/\/([A-z0-9]*)([\.]{1})([A-z0-9]{2,6})$/si'$url$matches);
                
$filename['original'] = str_replace("/"""$matches[0]);
 
                
// did we retrieve a valid filename?
                
$validurl iif(!empty($url) AND !empty($filename['original']), truefalse);
 
                
/*
                 * FOPEN Modification By Trigunflame
                 */
                // valid url
                
if ($validurl)
                {
                    
// init
                    
$data '';
 
                    
// cancel the file that might have been uploaded
                    
unset($_FILES["attachment{$key}"]);
 
                    
// attempt opening of remote file
                    
if ($fileOpen = @fopen($url"rb"))
                    {
                        while (!
feof($fileOpen))
                        {
                            
$data = @fread($fileOpen4096);
                        }
                        @
fclose($fileOpen);
                    }
 
                    
// empty
                    
if (empty($data))
                    {
                        
$error construct_phrase($vbphrase['error_cannot_retrieve_url'], $url);
                        
$errors[] = array(
                            
'filename' => htmlspecialchars_uni($url),
                            
'error' => $error
                        
);
                    }
 
                    
// save file
                    
else
                    {
                        
$tmp_name 'vbupload' substr(TIMENOW, -4);
                        
$filesize strlen($data);
 
                        
// write file to temporary directory...
                        
if ($vboptions['safeupload'])
                        {
                            
// ... in safe mode
                            
$filename['temp'] = $vboptions['tmppath'] . "/$tmp_name";
                            
$filenum = @fopen($filename['temp'], 'wb');
                            @
fwrite($filenum$data);
                            @
fclose($filenum);
                        }
                        else
                        {
                            
// ... in normal mode
                            
$filename['temp'] = tempnam(ini_get('upload_tmp_dir'), 'vbupload');
                            
$fp = @fopen($filename['temp'], 'wb');
                            @
fwrite($fp$data);
                            @
fclose($fp);
                        }
 
                        
$_FILES["attachment$key"]['name'] = $filename['original'];
                        
$_FILES["attachment$key"]['type'] = '';
                        
$_FILES["attachment$key"]['size'] = $filesize;
                        
$_FILES["attachment$key"]['tmp_name'] = $filename['temp'];
                        
$_FILES["attachment$key"]['error'] = 0;
                        
$_FILES["attachment$key"]['url_upload_by_curl'] = 1;
                    }
                }
            }
        } 


I get a filesize stats failed error with this code. ;)

Lionel 05-03-2005 05:12 PM

Can't get the fopen() code to work either.

Boofo 05-03-2005 05:44 PM

Quote:

Originally Posted by Lionel
Can't get the fopen() code to work either.

You get the same error?

Lionel 05-03-2005 05:46 PM

Can't tell as error has been turned off. I get a blank page, or nothing. I managed to upload only one url... from my site

akanevsky 05-03-2005 07:53 PM

Yeah...

1. The reason I used CURL library is safety. Originally, prior to installation of my hack, the code posted above would not work, as the is_uploaded_file function would not allow it. Right now, however, his code, would pose a security threat to your board, because it would tell the API that the file was uploaded by CURL and is safe, while that is not really true.

Therefore, the alternate code of yours is completely impertinent to the hack and I would like you to remove it. Thanks.

2. The code works for my site, however I set it to time out after 25 seconds of no response. Now, what exactly is the problem?

P.S. Please read here if you don't know why fopen is not safe:
https://vborg.vbsupport.ru/showthread.php?t=80541

Lionel 05-03-2005 08:34 PM

I kind of agree with Dark Visor. Someone posted a hack, if there is a problem, let him fix it. No need to hijack his thread. That only creates confusion. If you have a different idea, create your own thread.

Nordinho 05-10-2005 10:14 PM

hmmm...this seems interesting...so does it actually upload the file on the server?? that would save loads off red crosses...and is the original version working for all??

akanevsky 05-11-2005 09:14 AM

Quote:

so does it actually upload the file on the server??
Yes, it does. It creates a standard attachment, just as if you uploaded the file from your computer.

eplus_revenge 05-12-2005 12:07 AM

Dude,,i dont get any error..but after i click upload..it just says uploading..then nothign happens...

akanevsky 05-12-2005 07:18 PM

There is a timeout after 25 seconds. And it works only if you have Curl installed...

lange 05-14-2005 10:29 AM

Thanks.

akanevsky 05-14-2005 03:38 PM

I guess this could be moved to Final Releases?

jugo 05-14-2005 07:22 PM

It worked just fine for me...and i love it...time to place this puppy on the live boards!!!

quachvu 06-13-2005 08:17 AM

how can i change time out from 25s to 1 minute of more?

quachvu 06-13-2005 08:22 AM

Dude,,i dont get any error..but after i click upload..it just says uploading..then nothign happens... and i have alread installed curl

quachvu 06-13-2005 08:26 AM

Quote:

Originally Posted by Dark Visor
Sorry, I forgot to include that into the instructions. Will update them in a minute.

The fix is as follows:

In template 'newattachment', find:

Code:

if ((elm.type == 'file'))
and replace with:

Code:

if ((elm.type == 'file') || (elm.type == 'text'))

i just found
Code:

if (elm.type == 'file')
in my template ...

yoyoyoyo 06-13-2005 03:23 PM

Quote:

Originally Posted by Dark Visor
I guess this could be moved to Final Releases?

I installed this in 2 minutes, and it works as described! Thanks!

It would be nice to have "upload by URL" on the same line as the entry box, though, since it is kind of confusing, but otherwise works great!

akanevsky 06-13-2005 05:52 PM

quachvu,
I do not provide support for modified templates.

yoyoyo,
thanks :) Maybe I'll make it on one line. I'll see.

quachvu 06-14-2005 10:19 AM

its a original template and was not modified, and even i set up a fresh Vbulletin 307 forum and look in newattachment i just only can find this code in it

Quote:

var haveupload = false;
for (var i=0; i < formobj.elements.length; i++)
{
var elm = formobj.elements[i];
if (elm.type == 'file')
{
if (elm.value != "")
{
haveupload = true;

akanevsky 06-20-2005 05:51 PM

Sorry, my bad.
You would need to replace
PHP Code:

if (elm.type == 'file'

with
PHP Code:

if ((elm.type == 'file') || (elm.type == 'text')) 


logofreax 07-09-2005 10:54 AM

Thank youn for this Hack but i?ve got one Problem:

If I want to attach any File by URL I get this Error Message:

Quote:

Warning: filesize(): Stat failed for /kunden/73715_63755/domains/handy-faq.de/files/anhaenge/09783ad8c17c227c60f91d23b073d58c (errno=2 - No such file or directory) in /includes/functions_file.php on line 286
Can you please help me?

cu
logofreax

akanevsky 07-09-2005 12:08 PM

I don't think it has anything to do with my hack...


All times are GMT. The time now is 10:12 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01451 seconds
  • Memory Usage 1,909KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (4)bbcode_php_printable
  • (12)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete