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

It seems to me that Celada's reply fully answers your question: the only difference here is that now you want pass the name of the file to download as a parameter, whereas he hardcoded it. You only have to modify his code accordingly, obviously adding the necessary checks as needed.

Since you're using user input to return something from your local file system, I recommend you read some relevant document related to security issues. You may check the Tutorials section or Ovid's course.

Replies are listed 'Best First'.
Re^4: Showing Word document in browser
by Ernst (Initiate) on Jan 12, 2006 at 13:58 UTC
    Thanks for the quick answer but ..... I got this error message: Thu Jan 12 12:55:41 2006 error client 82.168.213.19 malformed header from script. Bad header=\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1: /www/cust/y/3/3/5/33515/cgi-bin/testword.pl The script is the hardcoded version and called testword.pl Maybe you can again think about me and my Perl problem.
    Greetings, Ernst Verster

      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.

        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