View Full Version : Attachment Upload by URL
akanevsky
04-30-2005, 10:00 PM
/*================================================= =====================*\
|| 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.php?p=648337&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.. ;)
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.
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 :)
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
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
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:
if (elm.type == 'file')
and replace with:
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
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.
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']), true, false);
/*
* 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($fileOpen, 4096);
}
@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
Then you did not install it correctly. What is your vB version?
Vbulletin Version 3.0.7
Boofo
05-03-2005, 02:59 PM
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.
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']), true, false);
/*
* 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($fileOpen, 4096);
}
@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
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
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?
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
Sorry, I forgot to include that into the instructions. Will update them in a minute.
The fix is as follows:
In template 'newattachment', find:
if ((elm.type == 'file'))
and replace with:
if ((elm.type == 'file') || (elm.type == 'text'))
i just found if (elm.type == 'file') in my template ...
yoyoyoyo
06-13-2005, 03:23 PM
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
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
if (elm.type == 'file')
with
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:
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...
yoyoyoyo
07-09-2005, 12:52 PM
I got the "or upload by URL:" phrase on the right line by changing this phrase:
or upload by url: to this:<br>or upload by url:
GrusPer
07-16-2005, 10:27 AM
Warning: filesize(): Stat failed for /home/grusper/public_html/files_points/random/83ec84548761132acc6ed40f21085c5f (errno=2 - No such file or directory) in /includes/functions_file.php on line 286
:((
Can you please help me?
akanevsky
07-16-2005, 01:53 PM
Are you running in safe mode?
Kirk Y
07-16-2005, 06:45 PM
Works great... although sometimes when I try to upload an attachment, everything seems to go fine but when I try to view the attachment, there's nothing there... just a white screen. It happened when I tried to attach some image from your site Dark Visor... that coding site.
akanevsky
07-16-2005, 06:54 PM
What site are you talking about??? I don't have any..
Kirk Y
07-17-2005, 05:20 PM
The Rent-A-Coder site; I clicked your Bio Link.
akanevsky
07-17-2005, 06:29 PM
Oh.. well maybe they have an anti-leech. That's not my site, it's a site I am a member of..
Kirk Y
07-17-2005, 10:40 PM
Yeah, I figured anti-leech may be the cause, but just thought I'd mention it, if that wasn't the case.
akanevsky
07-18-2005, 12:16 AM
Well do you get any error messages at all?
adill420
10-06-2005, 05:48 AM
ah man..thank you!!!!!
i didn't even know this hack was here!
once again thanks dark visor!
Replicators
10-31-2005, 12:41 PM
This is one hack i seriously need,but it doesn't work on 3.0.9 >8(
Is there any plans to make it compatible with 3.0.8 and higher?
akanevsky
10-31-2005, 07:54 PM
No, as I do not support the 3.0.x series anymore. I'd suggest you upgrade your board to 3.5, where this functionality exists by default.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.