#! /usr/bin/perl/bin/perl -wT use CGI; use strict; use File::Temp; use Archive::Tar; # Create CGI object and make array or params # The name will come from the HTML checkbox tags my $q = CGI->new(); my @selectedFiles = $q->param; # Create random $filename and .tar file with that name (my $fh, my $filename) = File::Temp::tempfile( "img_XXXX", SUFFIX=>'.tar' ); my $tar = Archive::Tar -> new ( $filename ); # Add the files to the .tar file and write it to disk $tar->add_files ( @selectedFiles ); $tar->write ( $filename, 0 ); ###### Here's the Trouble ###### # Send the .tar file to the browser print $q->redirect( $filename ); ################################ # Erase the .tar file from the server File::Temp::unlink0($fh, $filename) or die "Error unlinking $filename safely";