Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Beta Releases

Reply
 
Thread Tools
Attachment Upload by URL Details »»
Attachment Upload by URL
Version: 1.00, by akanevsky akanevsky is offline
Developer Last Online: Feb 2016 Show Printable Version Email this Page

Version: 3.0.7 Rating:
Released: 04-30-2005 Last Update: 06-19-2005 Installs: 11
 
No support by the author.

/*================================================= =====================*\
|| 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.

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #12  
Old 05-01-2005, 08:18 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #13  
Old 05-01-2005, 08:39 PM
Reminder's Avatar
Reminder Reminder is offline
 
Join Date: Oct 2004
Location: Istanbul
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #14  
Old 05-01-2005, 09:08 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your problem is in the javascript in template that checks for a value in upload field.
Reply With Quote
  #15  
Old 05-01-2005, 09:25 PM
akanevsky akanevsky is offline
 
Join Date: Apr 2005
Posts: 3,972
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'))
Reply With Quote
  #16  
Old 05-01-2005, 10:50 PM
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
Location: AnimationTalk.com
Posts: 2,367
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #17  
Old 05-01-2005, 11:17 PM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
                    }
                }
            }
        } 
Reply With Quote
  #18  
Old 05-02-2005, 12:18 AM
Allan's Avatar
Allan Allan is offline
 
Join Date: Jun 2003
Location: France
Posts: 1,513
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

screenshot please, just for looking ?
Reply With Quote
  #19  
Old 05-02-2005, 06:20 AM
Reminder's Avatar
Reminder Reminder is offline
 
Join Date: Oct 2004
Location: Istanbul
Posts: 32
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dark Visor
Then you did not install it correctly. What is your vB version?
Vbulletin Version 3.0.7
Reply With Quote
  #20  
Old 05-03-2005, 02:59 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #21  
Old 05-03-2005, 05:12 PM
Lionel Lionel is offline
 
Join Date: Dec 2001
Location: Delray Beach, Florida
Posts: 3,277
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:36 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06212 seconds
  • Memory Usage 2,416KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (2)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete