Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Grabbing files from the Web

Quote Reply
Grabbing files from the Web
Hi there. I’m having a bit of trouble here. I’m trying to grab a jpg file from the web.
Finding the link is no problem, but I have some difficulty getting the actual data
back to the server. If someone have a few tips for me, I'll appreciate it Wink


Sacrifice is not about what you lose,
it is about what you gain in the process.

Last edited by:

EZFrag: Feb 14, 2008, 12:49 AM
Quote Reply
Re: [EZFrag] Grabbing files from the Web In reply to
Hi,

Not really sure why you need to do this, but this should work:

Code:
sub {

my $file = '/path/to/file.jpg';
my $getimage = "http://www.site.com/image/to/get.jpg"

use LWP::Simple;
my @get = get($getimage)
open(WRITEIT,">$file);
foreach (@get) { print WRITEIT $_ }
close(WRITEIT);

return;
}

..or quicker yet:


Code:
sub {

my $file = '/path/to/file.jpg';
my $getimage = "http://www.site.com/image/to/get.jpg"

system(qq~wget -Ofile.jpg "$getimage"~);
# or may need to use:
`wget -Ofile.jpg "$getimage"`);

}

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Thanks Andy Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Finally, I'm relieved that I found something. Here is the code that made my day.

Code:

#!/usr/bin/perl -w

require CGI;
print "Content-Type: text/html\n\n";
use LWP::Simple qw( mirror is_error RC_NOT_MODIFIED );

my $query = CGI->new();
my $url = $query->param('url');
my $file = $query->param('file');

#$url = The location of the file you want
#$file = Where you want the file to be saved

my $status = mirror($url, $file);

if (is_error($status)) {

print "Can't get text file at URL $url\n";

}elsif($status == RC_NOT_MODIFIED) {

print "File $file not modified\n";

}else{

print "Well, check and see!";

}


Thanks again Andy. Here is the link where I found the code. http://www.perlmonks.org/index.pl?node_id=665585


Sacrifice is not about what you lose,
it is about what you gain in the process.

Last edited by:

EZFrag: Feb 14, 2008, 3:31 AM
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Hey Andy,

Hope all is well with you. EZfrag is helping me out a bit... here's what we're trying to do: We want to sumbit a remote image from the web via the add.html form template.

Creating the standard type=file form field will of course enable us to upload the image from our hard drives. Our problem is that the image is not avaialble locally, it lives somewhere remotely on the web. We know the URL to the image. I'd like the image to be sent with the rest of the form data when the "submit" button is clicked as it still needs to be processed by a thumbnailing plugin etc - just as it would have been had I uploaded it from my hard drive.

Any ideas? Smile

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Grabbing files from the Web In reply to
Hi,

Mmm.. thats pretty hard :/

What you would need to do - is have a hook on add_link , and then grab the image.

Then, the hard bit is getting it into the tables.

1) You would need to add the value into your field in the glinks_Links table
2) Then, add another entry (with the new path and URL to the image) into glinks_Links_Files
3) Finally, save the image into a hashed directory.

Getting the hash number is something like:

Code:
my $max_id = $DB->table('Links_Files')->select( ['MAX(ID)'] )->fetchrow; # get the highest ID, which should be the entry you just added
my $fletter = ( reverse split //, $fid )[0]; # get the hashed folder number from the ID.

...$fletter then holds the "hashed" folder ..i.e /path/to/file/$letter/$file

As you can see, not very easy =)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [sangiro] Grabbing files from the Web In reply to
I think there is a plugin that does almost everything you want, except that the original still besides on the remote server ... but this is not big deal to play with and modify the plugin to have the original on your hard drive.

Here: http://www.webster.de/...-plugins/index.shtml

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
How could I find out in what order Plugins are executed for a specific hook?


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Grabbing files from the Web In reply to
Hi,

Not sure what you mean?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Sorry about that. What I mean to say , is that , for example, the add_link hook can call multiple
subroutines from different plugins. But they can't be called all at once. The must be some sequence they are following
when they are called. Is there a way I can find out what that sequence is?

Thank you.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Grabbing files from the Web In reply to
Hi,

The only way I can think of, is looking in the plugins.cfg file, and seeing what order they show up in the file.

Look for :
Code:
hooks => {

}

..I believe they are called in the order they are found in that file (assuming they are the same, i.e add_link POST, and not one addl_ink PRE and another POST - as they are obviously called at different times :))

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Ok, Thanks Andy.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Grabbing files from the Web In reply to
BTW, if thats not right - you could always add some debug code in to check which ones are being called :)

Something like:
Code:
print $IN->header;
print qq~Running plugin: File.pm, on line: ~ . __LINE__ . "\n";

..and put that in the routines you are expecting to run - that way, you will know for sure which order they are being run in (and what line is being called, so you can be triple sure :D)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Hi again :)

I found the following code in one of the plugins use by the GLinks installation:

my (@args) = @_;

I am assuming that this is the parameters being passed to the plugins. I would like
to know what variables is stored in @_; and if it could be modified in any way.

I am thinking that the variables could be the same as those displayed with the DUMP.
Its only a thought, I just want to make sure...

Thanks


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Grabbing files from the Web In reply to
Hi,

I have to admit, I've never had to modify the value of @_ - but I'm sure you can =)

Normally, I just get the values via:

Code:
my (@args) = @_;

my $results = shift;

return @args if $results->{error};

$results is a hashref of the values passed in (in this case, "error")

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Grabbing files from the Web In reply to
Ah, ok.

Thanks


Sacrifice is not about what you lose,
it is about what you gain in the process.