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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top