Gossamer Forum
Home : General : Perl Programming :

Fetch from outside server

(Page 2 of 2)
> >
Quote Reply
Re: Fetch from outside server In reply to
Reason: subroutine cgierr is not defined.

Modified Code:


Code:
#!/usr/bin/perl


$datafile = "/home/usr/cgi-bin/test.txt";
@pairs = split(/&/, $ENV{'QUERY_STRING'});


foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$FORM{$name} = $value;
}


use LWP::Simple;
$file = get($FORM{url});


open (DATA, ">$datafile") or &cgierr("Error: Unable to open $datafile. Reason: $!");
print DATA "$file";
close (DATA);
chmod (0666, "$datafile") or &cgierr("Error: Unable to chmod $datafile. Reason: $!");


print "Content-type: text/html\n\n";
print "File fetched and saved!\n";
exit;


sub cgierr {


print "Content-type: text/html\n\n";
print "$_[0]\n";
}


Dan Smile


[This message has been edited by dan (edited February 14, 1999).]

[This message has been edited by dan (edited February 14, 1999).]
Quote Reply
Re: Fetch from outside server In reply to
When I do this it wont write to the file created? This can copy html right?e

------------------
elitecaraudio.com
carforums.com
Quote Reply
Re: Fetch from outside server In reply to
Dan, it's still "500". Even with this new code.

------------------
-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: Fetch from outside server In reply to
Ok, lets say that the script doesn't save the data for some reason. Frown
But can we make it to display data in the webbrowser? Smile

------------------
-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: Fetch from outside server In reply to
Man, this is getting crazy Smile

The script as outlined works fine for me. Remember to call the script as script.cgi?url=http://www.somewhere.com. It is case-sensitive (e.g., url and not URL) and the url must include http://

Pasha - I tested the script you are using (that you emailed to me) after changing the path to Perl & the datafile - it worked for me.

To print out the results, simply change:


Code:
open (DATA, ">$datafile") or &cgierr("Error: Unable to open $datafile. Reason: $!");
print DATA "$file";
close (DATA);
chmod (0666, "$datafile") or &cgierr("Error: Unable to chmod $datafile. Reason: $!");


print "Content-type: text/html\n\n";
print "File fetched and saved!\n";
exit;


to:


Code:
print "Content-type: text/html\n\n";
print $file;
exit;


Dan Smile
Quote Reply
Re: Fetch from outside server In reply to
Hi Dan!!

YES! it works using the..

print "Content-type: text/html\n\n";
print $file;
exit;

instead of the file saving part, so it looks as though what ever it is that is going wrong, is to do with the saving?!

Simon
Quote Reply
Re: Fetch from outside server In reply to
I don't know what to say, I guess, nothing's gonna work.
Here's the code I used:

#!/usr/bin/perl
$datafile = "/home/find/public_html/01/test.txt";
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$FORM{$name} = $value;
}
use LWP::Simple;
$file = get($FORM{url});
print "Content-type: text/html\n\n";
print $file;
exit;
sub cgierr {
print "Content-type: text/html\n\n";
print "$_[0]\n";
}
#End#

uploaded all in ASCII, (come on, I'm not that stupid) Smile

cmodding:
test.cgi - 755 - (rwxr-xr-x)
test.txt - 666 - (rw-rw-rw-)
/home/find/public_html/01/ - 777 - (rwxrwxrwx)

And yes, the path to perl is correct, at virtualave.net they told me that I can set either #!/usr/bin/perl or #!/usr/local/bin/perl (???) both will work. An yes, I've tested other sripts with both of these 'path to perl' they both work. But this bloody script just loooves to give me that nasty "500". Frown

Well, I got another night, "presidents day" is over, tomorrow school... going to spent this night toghether with my new good friend 'Perl 5'. Smile

At least I am not alone Smile

Pasha.

------------------
-[ It's just another night; good morning Webmasters! ]-
> >