Thank you, thank you!
I'm now making some progress. I could live with it as-is, I think, but would like, if possible, one more improvement: The Content-Length. I suppose, however, that is not possible when compressing on the fly.
I was already using Encode, so there was little more to adjust. I have now downloaded a zipped file successfully, which can be opened normally, with the following code.
sub exportdatabase { fork: { my ($recnum,$revnum,$book,$chap,$verse,$text) = ''; my @resp = (); my $timestamp = "$curdate_$curtime"; $timestamp =~ s/[\/:.]/-/g; my $to_windows = ''; my $CRLF = "\n"; if ($OS eq "Windows") { $to_windows = '--to-crlf'; # SAME AS -l $CRLF = "\r\n"; } my $zipfile = "$db_export_file.zip"; my $encoding = "UTF-8"; $statement = qq| SELECT a.RecordNum, a.RevisionNum, a.Book, a.Chapter, + a.Verse, a.Text from $table a INNER JOIN (SELECT RecordNum, max(Revi +sionNum) RevisionNum FROM $table GROUP BY RecordNum) b USING (RecordN +um,RevisionNum); |; &connectdb('exportdatabase'); push @resp, "RECORD#\tREVISION#\tBOOK#\tCHAP#\tVERSE#\tTEXT, AS EDITED + BY: $curdate $curtime (Pacific Time)$CRLF"; while (($recnum,$revnum,$book,$chap,$verse,$text) = $quest->fetchrow_a +rray()) { push @resp, "$recnum\t$revnum\t$book\t$chap\t$verse\t$text +$CRLF"; } binmode STDOUT; # just to play it safe print qq|Content-Type: application/zip, application/octet-stre +am$CRLF|; print qq|Cache-Control: no-cache, no-store, must-revalidate$CR +LF|; print qq|Accept-Ranges: bytes$CRLF|; print qq|Content-Language: utf8$CRLF|; #print qq|Content-Length: | . (stat $zipfile)[7] . "$CRLF"; print qq|Content-Disposition: attachment; filename="$zipfile";$CRL +F$CRLF|; my $z = IO::Compress::Zip->new('-', # STDOUT Name => "$db_export_file" ) or die "zip failed: $ZipError\n"; for my $line (@resp) { $z->print( encode($encoding, $line, Encode::FB_CROAK|Encode::LEAVE_SRC) ); } $z->close(); } #END fork } # END SUB exportdatabase
Without the Content-Length header, the client does not know how large the file being downloaded is, nor how long it will take. But, at least the file arrives intact!
In reply to Re^4: Correct Perl settings for sending zipfile to browser
by Anonymous Monk
in thread Correct Perl settings for sending zipfile to browser
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |