Sending a pdf file with perl
am 30.08.2007 04:42:42 von 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
Re: Sending a pdf file with perl
am 30.08.2007 05:35:01 von Gunnar Hjalmarsson
Bill H wrote:
> 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;
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl