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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.