To those more Monkier than I,

Here's a self-imposed project that's already stretched me a lot, but has left me seeking more wisdom. I have a friend in CA who wants me to send her several hi-resoluction (600dpi) .jpg files. But she doesn't know what pictures I have available, and I don't know what she wants. So I was just going to make an HTML page of thumbnails (72dpi) that link to the hi-res images. This could be done in plain simple straight-forward HTML. But instead I smelled a learning opportunity ;)

I want to make a simple HTML page of the low-res thumbnails, but each thumbnail will have it's own checkbox. The user can scroll down the page, select the images she wants to have high-res copies of, then hit submit. The CGI script will add the hi-res files to a .zip file and generate a new HTML doc with directory list of the new .zip and a link to download the file. Looking at CPAN I found Archive:Zip and came up with this code:
#! /usr/bin/perl -wT # PSUEDO CODE # 1. Plain HTML page with check-boxed thumbnail images # 2. On submit() hi-res copies of the selected images are # added to a .zip file # 3. A new page is displayed listing the content and size # of the file with a link to the newly created file # 4. Once the file is downloaded it will be erased from the # server. (better to prompt the user to erase?) use strict; use CGI; use Archive:Zip; # Archive:Zip POD is at # http://theoryx5.uwinnipeg.ca/CPAN/data/Archive-Zip/Archive/Zip.html # Make a new CGI object my $q = CGI->new(); # Create an array of the file names (drawn from the name # tag in the HTML) to be added to the zip file my @selectedFiles = $q->param; # How to name the .zip file without risk of duplication? my $fileName= ####; my $zip=Archive:Zip->new($fileName); # Add the files to the zip file foreach my $key(@selectedFiles) $zip->addfile ($key); # Draw a new HTML page listing the .zip file contents plus # a link to download the file print $q->header( "text/html" ), $q->start_html(-title => "Directory of $fileName.zip", -bgcolor => "#ffffff" ), $q->h1( "Contained in $zipFileName" ), $q->start_ul; # for each member-file in the .zip file, print the file # as a list item foreach $key($zip->members()) print $q->li("$key"); print $q->end_ul, $q->p( "File Size: stat($fileName.zip)[7]" ), $q->a( "Download $fileName.zip", $fileName+".zip" ), $q->end_html;

I see a few new questions popping up as I look at the code I've created:
  1. How do I create a new/unique file name for each instance the script is ran (in reality probably only one person would use this script once, but I'm trying to learn here!)? How do I do it safely?
  2. How can I have the server erase the file once it is downloaded?
  3. How can I tell the script to erase the file if it isn't downloaded within, say, ten minutes (to keep some cracker from filling the server with huge .zip files just for kicks)?
Yes, I could do the whole project without Perl, but what a wasted opportunity! Any ideas on how to deal with these issues? Or any ideas for places to look? Thanks for your experience!

Cheers!
Petras
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 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.