#!/usr/bin/perl use warnings; use strict; use CGI::Simple; use IO::Compress::Zip qw/$ZipError/; use Encode qw/encode/; my @lines = (qw/ Hello World Foo Bar /, "\N{U+1F42A}"); my $CRLF = "\r\n"; my $encoding = "UTF-8"; # or maybe "CP1252" for Windows my $zipdata; my $z = IO::Compress::Zip->new(\$zipdata, Name => "Filename.txt" ) or die "zip failed: $ZipError\n"; for my $line (@lines) { $z->print( encode($encoding, $line.$CRLF, Encode::FB_CROAK|Encode::LEAVE_SRC) ); } $z->close(); my $q = CGI::Simple->new(); print $q->header( -type => 'application/zip', -Content_Disposition => qq{attachment; filename="Download.zip"}, -Content_Length => length($zipdata) ); binmode STDOUT; # just to play it safe print $zipdata; #### $z->print( encode( $encoding, "RECORD#\tREVISION#\tBOOK#\tCHAP#\tVERSE#\tTEXT, AS EDITED BY: $curdate $curtime (Pacific Time)$CRLF", Encode::FB_CROAK|Encode::LEAVE_SRC ) ); while ( ( $recnum, $revnum, $book, $chap, $verse, $text ) = $quest->fetchrow_array() ) { $z->print( encode( $encoding, "$recnum\t$revnum\t$book\t$chap\t$verse\t$text$CRLF", Encode::FB_CROAK|Encode::LEAVE_SRC ) ); }