Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Re: Need help with a simple Perl script

Thread Tools

Re: Need help with a simple Perl script

Posts: n/a
On Wed, 28 May 2008 22:40:28 -0400, Dick Sutton 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...
> Dick

Grab the file content and print it out after your type header...

@file = <FILE>;

print "Content-Type:application/pdf\n\n";
print @file;

- Netlurker
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to call a simple perl script from HTML without need of HTTPS but simple HTTP ? Wladimir Borsov Perl Misc 4 05-11-2006 09:29 AM
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM