Sending a pdf file with perl

B

Bill H

In one of my perl scripts I need to send a visitor a pdf file when
they visit a web page. Since the pdf file is not in "public" space on
the server, I need to send it to them instead of using a
"Location: ....". I use MIME:Lite for email pdf's on another site, is
there a similar thing for sending pdf's to a browser or can I use
Mime:Lite?

Bill H
 
G

Gunnar Hjalmarsson

Bill said:
In one of my perl scripts I need to send a visitor a pdf file when
they visit a web page. Since the pdf file is not in "public" space on
the server, I need to send it to them instead of using a
"Location: ....". I use MIME:Lite for email pdf's on another site, is
there a similar thing for sending pdf's to a browser or can I use
Mime:Lite?

When you let the visitors download a file, you print to STDOUT, which is
quite another thing. Example code:

open my $fh, '<', "$path/$filename" or die $!;
binmode STDOUT;
print "Content-Type: application/pdf\n",
"Content-Disposition: attachment; filename=$filename\n",
'Content-Length: ' . (stat "$path/$filename")[7] . "\n\n";
while ( read $fh, my $buffer, 1024 ) {
print $buffer;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top