Re: perl - sending an existing file to browser.

by "Jason K. Chapman" <theguild(at)interserv.com>

 Date:  Mon, 04 Jun 2001 06:37:36 -0400
 To:  <hwg-techniques(at)hwg.org>
 In-Reply-To:  dad
  todo: View Thread, Original
At 01:38 PM 6/4/2001 +1200, peter newton wrote:
>I've no problem with anything except how to send an EXISTING html file,
>usually I create it on the fly within the script but in this case I just
>want to select an appropriate file that already exists.

I'm assuming you know the name of the files being selected.

# Make the file choice based on the form
# and put the file name into something like $filename
#
# then...
open(HTML,"<$filename");
my @lines = <HTML>;
close(HTML);

print "Content-Type: text/html\n\n";
foreach $line (@lines) {
   print $line;
}

Or......

$url = "http://$domain_name/$filename";
print "Location: $url\n\n";

The advantage of reading the file in and printing it out is that you get 
the opportunity to do any necessary s/// template substitutions.

As always, with Perl, there are a few dozen other ways to do it.  Which one 
you use depends on the specifics of the task.

Jason K. Chapman
--
THE HERETIC, a cyber thriller by Jason K. Chapman.
Online edition at <http://www.happyhacker.org/heretic/>. Softcover,
ISBN 1-929925-38-7. Latest news at <http://www.jasonkchapman.com>

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA