Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

mod_perl behavior w/out mod_perl

by janos.gonzales (Novice)
on Mar 12, 2008 at 21:19 UTC ( [id://673830]=perlquestion: print w/replies, xml ) Need Help??

janos.gonzales has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to build a CGI script so that when my Apache server is asked for http://myserver.com/test/123.pdf then the CGI script fires up and serves the file.

The reason for this is that the file does not really exist in the 'test' folder at all but on a different machine. I figured out how to get the CGI script to copy this file and serve it and 'fool' the browser into thinking it's loading a PDF. What I need now is for the address in the url to be http://myserver.com/test/123.pdf not http://myserver.com/test/script.pl . This is so that when the file is saved it's saved with its real name not as a PDF with a wrong .pl extension.

Do I have to use mod_perl for this? Or is there an easier way?

Thanks Monks

Replies are listed 'Best First'.
Re: mod_perl behavior w/out mod_perl
by samtregar (Abbot) on Mar 12, 2008 at 21:32 UTC
    What headers are you setting when you serve the PDF? You should be able to set a content disposition header that gives the browser a filename to save-as. Something like (modulo the package you're using to do CGI):

    print $query->header(-content_disposition => 'attachment;filename=123. +pdf', ...);

    -sam

      I figured it out! I just use Apache's Action directive (http://httpd.apache.org/docs/1.3/mod/mod_actions.html#action)

      AddHandler my-file-type .pdf Action my-file-type /scripts/scrip.pl

      The filename headers I give the output does not change the Title of the file when displayed in the browser, nor does it change the default file name that appears in the save prompt when you try to save the file.

Re: mod_perl behavior w/out mod_perl
by gwhite (Friar) on Mar 12, 2008 at 21:40 UTC
    I use a cgi header something like this:

    print $cgi->header(-type=>'application/pdf', -attachment =>'123.pdf' +);

    g_White
Re: mod_perl behavior w/out mod_perl
by jperlq (Acolyte) on Mar 13, 2008 at 00:19 UTC
    hi janos,
    I'm not sure if there is a specific reason you want to load the 123.pdf from a cgi script (if there is then probably stop reading here).

    If you simply give the "http://myserver.com/test/123.pdf" as a link the http will automatically serve up the .pdf object (ie. so that when a user clicks on a link -- the 123.pdf file will automatically download).
    There is not so much need to use the CGI module -- http is built to retrieve and serve objects such as this.

    This has been my experience. I hope it helps.
    Best of Luck,

      I'm not sure if there is a specific reason you want to load the 123.pdf from a cgi script.

      janos.gonzales mentioned that the file 123.pdf does not really exist, but is dynamically generated by the CGI (in this case fetched on-demand from a different server).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://673830]
Approved by samtregar
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found