in reply to Re: Download Word Docs
in thread Download Word Docs

Sorry about not including the code. I'm new here. It's below. The error message I received was a vague MS message as I noted in my first request: 'The document or path is invalid. Try using the Word open dialog.' No clue what that means.

Anyway, your suggestion to compare the files led to a clue. It turns out that my read buffer size was too small.

Thanks for your help. Please give me any other helpful hints if you see something I could improve.

#!/usr/bin/perl -wT

use strict;
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
use Archive::Zip;
use Archive::Zip::MemberRead;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $files_location;
my $ID;
my $FN;
my $buffer;
my @filespec;

$files_location = "/home/public_html/test";

$ID = param('ID');
$FN = param('FN');

if ($ID eq '' || $FN eq '') {
print "Content-type: text/html\n\n";
print "Invalid Request";
} else {
local($/) = undef;
my $zipName = "$files_location/$ID";
my $zip = new Archive::Zip($zipName);
my $fh = new Archive::Zip::MemberRead($zip, $FN);
my $read = $fh->read($buffer, 1024*1024);
die "FATAL ERROR reading my secrets !\n" if (!defined($read));
$fh->close();
binmode STDOUT;
@filespec = split("/", $FN);
#print "Content-Type:application/x-download\n";
print "Content-Type:application/msword\n";
print "Content-Disposition:attachment;filename=$filespec1\n\n";
print $buffer;
}

sub Error {
print "Content-type: text/html\n\n";
print "The server can't use $_[0] and $_1: $! \n";
exit;
}