in reply to opening a file for printing

You're opening $location using the append mode (>>) but you're trying to read from it. You're also not printing any HTTP header at all. And if you don't supply a MIME type, the browser won't know what to do with the data. What kind of data is this, and what do you want the browser to do with it?

Replies are listed 'Best First'.
Re^2: opening a file for printing
by sulfericacid (Deacon) on Feb 16, 2005 at 17:51 UTC
    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
      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