0

I'm trying to read in a file to my perl script and then set the headers appropriately based on the filetype. PDFs are not displaying and i'm thinking that my server guy has this thing locked down. Is there anything that I may be doing wrong with this script?

my $q = CGI->new;   #instantiate the CGI object
my $filename = $q->param('file');   # get the file param from the query string
my $text = read_file($filename);    # read in the file

my($name, $path, $suffix) = fileparse($filename, qr/\..*/);

if($suffix eq ".pdf") {
    print $q->header('Content-type: application/pdf');
} else {
    print $q->header('text/html');
}
Catfish
  • 18,876
  • 54
  • 209
  • 353
  • What are the actual headers you're seeing on the client side? – friedo Dec 20 '11 at 22:06
  • application/pdf. I checked with firebug in the net panel. – Catfish Dec 20 '11 at 22:08
  • What did the server guy say when you asked him? – tadmc Dec 20 '11 at 22:26
  • He wants it locked down. He gave us 1 folder for pdfs, but we're moving some very old complicated stuff with html and pdf in the same dir. I was hoping with a script I could display the pdf rather than having to modify some other beast to split the files. The tough part is things get generated daily. – Catfish Dec 20 '11 at 22:32

1 Answers1

4
$ perl -MCGI -E'my $q = CGI->new; print $q->header("Content-type: application/pdf");'
Content-Type: Content-type: application/pdf; charset=ISO-8859-1

You are generating an invalid header. Use either 'application/pdf' or -type => 'application/pdf' or 'Content-Type' => 'application/pdf' as arguments to the header method.

daxim
  • 39,270
  • 4
  • 65
  • 132