in reply to Showing Word document in browser

It looks like you are trying to build a multipart MIME entity containing the document (because of your use of boundaries) but you haven't got the right type on it. But:

Also, you get $bufsize to 60*57 (any special reason to pick this number 3420?) and you loop as long as it is still equal to 3420, which it always is since you never change it. It will loop forever.

What you need to do is far simpler:

if (open (INHOUD, "$regel")) { binmode INHOUD; print << "EOT1"; Content-Type: application/msword; filename="bw051122.doc" EOT1 while (read(INHOUD, $buffer, 4096) { print $buffer; }; close (INHOUD);

As a bonus, if you always send the same document, you could add Last-Modified and Expires headers to enable the client to cache the result just like if you have been able to do if the web server had served the file directly.

Replies are listed 'Best First'.
Re^2: Showing Word document in browser
by Ernst (Initiate) on Jan 12, 2006 at 12:57 UTC
    Thank's but I think I didn't tell it right. Let say there is a Word document /docs/word/wordfile.doc but I don't like that visitors can see this path. So I make a Perlscript showdoc.pl?wordfile.doc What does that Perl script had to do. Now I hope I said it in a good way Greeting Ernst
    Greetings, Ernst Verster

      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.

        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