Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Filter apache web get request using cgi-perl

by scorpio17 (Monsignor)
on Jun 07, 2012 at 13:23 UTC ( #974939=note: print w/ replies, xml ) Need Help??

in reply to Filter apache web get request using cgi-perl

You should take a look at the Apache module MOD_REWRITE.

It will let you map a URL like this:

into something like this:

However, it might be a good idea to use some kind of id number, instead of the actual file name, in the URL. Then the script could use that id to do a database lookup, and get the path, filename, etc.

Using the actual filename may cause problems if it contains spaces, or other non-URI safe characters, for example.

The PDF files need to be in a directory NOT under the HTML document root (i.e., it needs to be impossible to access them by URL, else your system can be easily bypassed. Your script will need to read the requested PDF and then write it back out. Make sure to set the mime-type correctly in the html header (something like 'application/pdf'). This way if you have an index page listing all your files, when someone clicks on a link, the browser won't load a new page, but the pdf will open up in a new window. Note that the exact behavior may vary depending on which browser is being used, and what plugins have been installed, etc. Some people like for pdfs to open inside the browser, others prefer to launch a pdf reader on the side, while others may prefer to get the "save as" dialog and view it later. The mime type may help give you some control over this.

Comment on Re: Filter apache web get request using cgi-perl
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://974939]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (17)
As of 2014-11-27 10:06 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (183 votes), past polls