File::Temp worked out well, and was surprisingly easy to learn. Actually the whole script turned out to be surprisingly short and simple to write. I don't know why you ever let me waste time with that other language at all!

As short as it is, this is my most complex Perl project yet and there's one part I just can't find an easy solution for. Here's the html that calls the cgi:
<html> <body> <form action='../cgi-bin/maketar.cgi' method='post'> <input type=checkbox name="1.text">1<br> <input type=checkbox name="2.text">2<br> <input type=checkbox name="3.text">3<br> <input type=checkbox name="4.text">4<br> <input type=checkbox name="5.text">5<br> <input type=submit> </form> </body> </html>
And here is the actual script. It's shorter and pretier, but I can't get it to force a download of the new file (oh, I should mention that on advice of fglock I went to Archive::Tar instead of Archive::Zip):
#! /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=>'.t +ar' ); 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";
CGI::Push isn't going to do it, I don't think. What happens with the code as is, using Indigo Perl's Apache bundle locally on my machine the script creates a .tar file, tries to display the contents, can't and the script runs again, creating an infinite (until I intervene) number of .tar files in the cgi-bin directory. On my webserver it makes one .tar file, then shuts down. RTFMing is proving quite educational, but I'm not seeing a way to open a download file box. I could do something like:
print $q -> start_html, $q -> a ( "$filename", $filename ), $q -> end_html;
but I'd like to avoid that if possible. Any way I could?

Cheers,
-P
Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.

-Howard Aiken

In reply to Re: Re: Non-Duplicate File Names, Security, and Self Cleaning by Petras
in thread Non-Duplicate File Names, Security, and Self Cleaning by Petras

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.