Re: Need help with a simple Perl script

Discussion in 'Perl' started by Netlurker, May 29, 2008.

  1. Netlurker

    Netlurker Guest

    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...

    open(FILE,"<$pdffile");
    @file = <FILE>;
    close(FILE);

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

    - Netlurker
    Netlurker, May 29, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,501
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,765
  3. pj
    Replies:
    3
    Views:
    273
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    125
    Paul Lalli
    Jan 5, 2005
  5. Wladimir Borsov
    Replies:
    4
    Views:
    280
    Tintin
    May 11, 2006
Loading...

Share This Page