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"; } $statement = qq| SELECT a.RecordNum, a.RevisionNum, a.Book, a.Chapter, a.Verse, a.Text from $table a INNER JOIN (SELECT RecordNum, max(RevisionNum) RevisionNum FROM $table GROUP BY RecordNum) b USING (RecordNum,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_array()) { push @resp, "$recnum\t$revnum\t$book\t$chap\t$verse\t$text$CRLF"; } chdir $exportdir or print "Cannot change directory to $exportdir\n"; { open TARGET, ">$db_export_file" or die "Cannot export the database to a file. Please contact the system administrator.\n"; print TARGET @resp; close TARGET; } my $zipfile = "$db_export_file.zip"; #TO escape the 'taint' function on the $ENV{PATH} $ENV{'PATH'} =~ /(.*)/; $ENV{'PATH'} = $1; # -T test the file # -l flag will convert to CRLF line endings (Windows) # -to_crlf convert to CRLF line endings (not for binary files) my $command = `/usr/bin/zip -T $to_windows $zipfile $db_export_file`; if ($zipfile eq '') { print "Content-type: text/html\n\n"; print "You must specify a file to download.\n
";
} else {
open FILE, "<$zipfile" or die "Can't open $zipfile ... $!";
# open(FILE, "<:raw:perlio", $zipfile);
binmode FILE;
# binmode FILE, ":encoding(UTF-8)";
print qq|Content-Type: application/x-download\n|;
#print "Content-Type: application/zip\n\n",
print qq|Content-Length: | . (stat $zipfile)[7] . "\n";
print qq|Content-Disposition: attachment; filename="$zipfile";\n\n|;
while (