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

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

Replies are listed 'Best First'.
Re^7: Showing Word document in browser
by blazar (Canon) on Jan 12, 2006 at 16:31 UTC

    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...