in reply to Re: opening a file for printing
in thread opening a file for printing

I know I'm not printing an HTTP header yet, that's one of the questions I had was which one I should use?

Or should I use a module like gaal suggested that determines the mime type of the file before opening it?



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re^3: opening a file for printing
by friedo (Prior) on Feb 16, 2005 at 18:07 UTC
    You can try to guess the MIME type using File::MimeInfo, but be warned that it's not perfect and may make mistakes.

    use strict; use File::MimeInfo; # ...get $location from DB.... my $mtype = mimetype($location); open my $fh, $location or die "Could not open $location: $!"; print "Content-type: $mtype\n\n"; print while <$fh>;
      I did install File::MimeInfo (was a tricky thing to install, might I add. lol) and it does half-sorta work.

      I have a test image and a test pdf file in the DB just to see if they load.

      The image loads perfectly. It loads as script.pl?download=8 and when you right click it, you can't see the original source and you can't view the page source. AWESOME!!

      However, when loading the PDF file it doesn't work at all. It says:

      File Download... Filename: accessfiles.pl File type: Adobe Acrobat Control for ActiveX From: domain
      I can't download it because it's a .pl file but it won't load either. Any suggestions?


      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        Make sure you're sending the right header. Try spitting it to STDERR and looking in the erorr log after you make your request. It should be "Application/pdf". If not, you'll need something smarter than File::MimeInfo.

        It also could be that your browser is improperly configured to deal with PDFs.