sub write_and_download{
[...]
$self->generate_zip();
$self->download_file();
my $filename = "temporary/" . $projectname . ".zip";
unlink $filename;
};
sub download_file{
my $self = shift;
my $downloadfile = $projectname . ".zip";
my $fullpathdownloadfile = "temporary/$downloadfile";
my $output = '';
my $buffer = '';
open my $fh, '<', $fullpathdownloadfile
or return error_handler("Error: Failed to download file $downloadfile:
$!
");
while (my $bytesread = read($fh, $buffer, 1024)) {
$output .= $buffer;
}
close $fh
or return error_handler("Error: Failed to download file $downloadfile:
$!
");
my $downloadfilesize = (stat($fullpathdownloadfile))[7]
or return error_handler("Error: Failed to get file size for $downloadfile:
$!
");
$self->header_props(
'-type' => 'application/x-download',
'-content-disposition' => "attachment;filename=$downloadfile",
'-content_length' => $downloadfilesize,
);
return $output;
};