Re: Need help with a simple (I think) Perl script
- From: Bill H <bill@xxxxxxxxx>
- Date: Thu, 29 May 2008 02:34:50 -0700 (PDT)
On May 28, 11:01 pm, "*** Sutton" <rsutto...@xxxxxxxxxxx> wrote:
First of all, I am a rank amateur at Perl. Here is my problem: I have a
hundred or more files in a directory on a web server (let's call it
'Library'). Each file is a pdf file and is named 'yyyymmm.pdf' where yyyy
is the year (i.e. 2007) and mmm is the first 3 letters of the month (i.e.
Jan). So a typical file name looks like '2007Jan.pdf'.
I wrote a simple html page using FORM that allows the user to select the
year and the month and then press the SUBMIT button and I want the
respective pdf file returned into the users browser. The problem is, I
don't know how to return a pdf file to the browser.
Here's what I have so far:
#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard';
# declare variables...
my $year;
my $month;
my $pdffile;
# get the parameters...
$year = param('Year');
$month = param('Month');
# construct the relative pathname to the actual PDF file
$pdffile = '../Library/'.$Year.$Month.'.pdf';
print 'Content-type: application/pdf\n\n';
This is where I'm stuck. Can someone push me in the right direction. I
would think it should be trivial. I just don't know how to procede.
Thanks in advance...
***
Unless you do not want the visitor knowing where the pdffile is on
your server, I would use the following instead of the print 'Content-
type: application/pdf\n\n';
print "Location: yourwebdomain/Library/$pdffile\n\n";
This way you are not streaming the pdffile through perl and are
instead letting the server just serve it up. Also you should check
that the $year and $month are valid entries on the off chance that
someone tries to feed the script bogus or empty values.
Bill H
.
- Follow-Ups:
- Re: Need help with a simple (I think) Perl script
- From: *** Sutton
- Re: Need help with a simple (I think) Perl script
- References:
- Need help with a simple (I think) Perl script
- From: *** Sutton
- Need help with a simple (I think) Perl script
- Prev by Date: Re: Remove a tab with backspace?
- Next by Date: Re: Remove a tab with backspace?
- Previous by thread: Re: Need help with a simple (I think) Perl script
- Next by thread: Re: Need help with a simple (I think) Perl script
- Index(es):