Gossamer Forum
Home : General : Perl Programming :

print "Location:" in combination with pdf-files.

Quote Reply
print "Location:" in combination with pdf-files.
Hi,

Didn't visit this forum for a long time, so all coding when't fine....... Tongue

But, today I wanted to implement the following sub in a script. The only thing is that the visitor can see the original location in the addressbar of the browser. I tried to to let the script read the pdf-file and output it, but didn't succeed on the (correct) outputting. Actually, that wouldn't be a smart solution because the most pdf-files I would like to offer are rather big.

Does anyone has a good solution or idea?

Code:


sub pdf_download {
# --------------------------------------------------------
my $filename = shift;
my $location = "http://www.domain.com/secure" . $filename . ".pdf";
print "Location: $location\n\n";

}
Quote Reply
Re: [Perlboy Chris] print "Location:" in combination with pdf-files. In reply to
If you don't want your user to see the URL and to trick them into thinking that the script was actually sending out the PDF to their browser, I would use something like this:

Code:
sub pdf_download {
# --------------------------

my $file = shift;

my $file_location = "/path/to/secure" . $file . ".pdf";

my $pdf;

open(FH, "/path/to/secure/$file.pdf");
$pdf = <FH>;
close FH;

print $query->header('application/pdf');

print $pdf;
}

This assumes that the file is on the same server as the script is being called from. If not, then you'd replace the file handle lines with maybe a LWP::Simple get routine which isn't a problem.

Update: You'd probably want to look into buffering here, too, especially if it's going to be big PDFs you're pushing to the browser.

Hope this helps.

- wil

Last edited by:

Wil: May 23, 2002, 3:37 PM
Quote Reply
Re: [Wil] print "Location:" in combination with pdf-files. In reply to
Hi,


I would need a different solution then 'reading and outputting' because the PDF's are rather big. What about if I changed my old solution from:

Code:
my $location = "http://www.domain.com/secure" . $filename . ".pdf";

into:

Code:
my $location = "/secure" . $filename . ".pdf";

=> It works (the user can't see the orginal location) with IE5.5, but doesn't know the general results with other browsers and systems?

Last edited by:

cK: May 25, 2002, 9:41 AM
Quote Reply
Re: [cK] print "Location:" in combination with pdf-files. In reply to
In this case you'd better off using CGI.pm built-in redirect function rather than printing the header this way.

- wil