in reply to Re^4: Showing Word document in browser
in thread Showing Word document in browser

Well, I have not much experience with CGI programming. But if you tried his code as is then it's obvious it won't work. It's meant to be only a snippet. In particular you'll notice that there's a $regel variable that is supposed to be a full (relative or absolute) path to your document, but if you didn't set it explicitly, then it will be undefined. Sorry if I'm pointing out something obvious - if not then you should really read some introductory text about Perl first, and then some CGI tutorial as already advised. I may be wrong but I'm getting the impression that you're just copying and pasting code from somewhere else without really understanding it.

Replies are listed 'Best First'.
Re^6: Showing Word document in browser
by Ernst (Initiate) on Jan 12, 2006 at 15:03 UTC
    Sorry that I'm not good enough in expressing the idea in English. I do program enough in Perl and this is my testgif.pl script. Maybe this example is better.
    =================================
    in the html code I'm using is (ofcourse with the html-symbols around it:

    img src="../cgi-bin/testgif.pl?werkplek.gif"
    ==================================
    The Perl script is:

    #!/bin/perl5.005_03 -w

    use strict;
    use CGI qw(:all);
    my ($buffer);
    if (open (INHOUD, "../docs/gemjcw/doc/sb/werkplek.gif")) {
    binmode INHOUD;
    print << "EOT1";
    Content-Type: application/msword; filename="werkplek.gif"
    EOT1
    while (read(INHOUD, $buffer, 4096)) {
    print $buffer;
    }
    close (INHOUD);
    exit;

    ==========================
    And the result is "Thu Jan 12 14:37:10 2006 error client 82.168.213.19 malformed header from script. Bad header=GIF89a(: /www/cust/y/3/3/5/33515/cgi-bin/testgif.pl"
    ==================================
    Greetings, Ernst Verster

      As I already said, I'm far from being an expert in this field of application. But apart that

      • (I'd switch to a more recent perl if possible and) use warnings instead of -w;
      • use a lexical filehandle and the 3-args (with "<:raw") form of open,

      at first sight the only thing that I can guess is that

      Content-Type: application/msword;

      doesn't play well with a gif file: indeed the header is recognized as a GIF89a as printed in the error message. Did you try with an actual word doc? How 'bout a plain application/octet-stream if that doesn't work either? I for one would be happier to just download it rather than to directly open it even if I were on a Windows box...