in reply to Opening PDF through CGI

At a first glance it should work.

open(FIN,"< $full_path") || print "File Not Found"; binmode FIN; $buffer = join '', <FIN>; close(FIN); print $buffer;

BTW: how 'bout:

open my $fin, '<:raw', $full_path or die WHATEVER; local \$; # or use File::Slurp print <$fin>;

Update:The following appears to work:

#!/usr/bin/perl -T use strict; use warnings; use CGI ':standard'; use CGI::Carp 'fatalsToBrowser'; print header('application/pdf'), do { open my $fh, '<:raw', 'minimal.pdf' or die "D'Oh! $!\n"; local $\; <$fh>; }; __END__

(it is temporarily available at http://blazar.perlmonk.org/tmp/minimal.pl)

Replies are listed 'Best First'.
Re^2: Opening PDF through CGI
by nobull (Friar) on May 26, 2006 at 16:58 UTC
    print header('application/pdf'), do { open my $fh, '<:raw', 'minimal.pdf' or die "D'Oh! $!\n"; local $\; <$fh>; };

    Due to the funny way CGI::header() operates under mod_perl it is advisable to always print the result of CGI::header immediately and never defer it. In this particular case it probably doesn't matter but one day it may.

    print header('application/pdf'); { open my $fh, '<:raw', 'minimal.pdf' or die "D'Oh! $!\n"; local $\; print <$fh>; };

    Note: the above code slurps the whole PDF into memory. I prefer to use File::Copy

    use File::Copy 'copy'; print header('application/pdf'); copy 'minimal.pdf', \*STDOUT or die "D'Oh! $!\n";