Hello all, I'm trying to create an upload script that allows the user to enter a name for a song and then also upload the actual file. I have been succesful in getting a script to upload the actual file and also allow the user to delete uploaded files. Now I have added a field where the user can input the name of the song. So I would like to be able to have the user input the name of the song and upload the file and also be able to delete the name of the song and the file. The only thing I can think of to make this work is to create a hash the stores the file name as the key and the song title as an element. However I am not very good with hashes. I have tried doing this to create the hash:
my %test = qw( @song_titles, @song_files );
This does not work but it was the only thing I could think of to get arrays into a hash. @song_titles is being stored in a txt file and I get the data for @song_files by globbing the relevant directory. Here are the relevant sub routines:
#### # Upload HTML #### sub upload_html { print<<HTML; <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO +-8859-1"> <title>Upload</title> </head> <body bgcolor="#ffffff"> <form action="upload.cgi" Method="post" ENCTYPE="multipart/form-da +ta"> <P>Please choose a file to upload: <INPUT TYPE="FILE" NAME="file"> <BR> Name of Song: <INPUT TYPE="TEXT" NAME="f_name"> <INPUT TYPE="HIDDEN" NAME="page" Value=$page> <br> <br> <INPUT TYPE="submit" NAME="action" VALUE="Submit"> <INPUT TYPE="submit" NAME="action" VALUE="Delete"> </FORM> <p></p> HTML chdir "/Library/WebServer/Documents/userpages" or die "Can't set path +for dir: $!\n"; # make directory for user # first check to see if it exists unless (-e $page) { mkdir("$page", 0777) || die "cannot make directory for $page: $!"; } } #### end of upload html #### # Get File List #### sub get_file_list { # set path chdir "/Library/WebServer/Documents/userpages/$page" or die "Can't set + path for dir: $!\n"; my $url = "/userpages/$page/"; my @files=glob("*.*"); print<<HTML; <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO +-8859-1"> <title>Upload - Delete Files</title> </head> <body bgcolor="#ffffff"> <form action="upload.cgi" Method="post" ENCTYPE="multipart/form-da +ta"> <P>List of Files: <br> <INPUT TYPE="HIDDEN" NAME="page" VALUE="$page"> HTML foreach (@files) { print "<br> Delete this File: $_ <INPUT TYPE=\"checkbox\" NAME=\"files +\" VALUE=\"$_\">\n"; } foreach (@files) { print "<br> View <A HREF=\"$url$_\">$_</a>\n"; } print<<HTML; <br> <br> <INPUT TYPE="submit" NAME="action" VALUE="Remove File( +s)"> </FORM> HTML } ### end of get file list #### # Delete File #### sub delete_file { # set path chdir "/Library/WebServer/Documents/userpages/$page" or die "Can't set + path for dir: $!\n"; $page =~ /^([\w.]+)$/; # The "untainted" file is now in $1 $page = $1; die "Bad filename for value page" unless $page; # check for tainted data my $files = $q->param( "files") || error( $q, "couldn't read File valu +es"); $files =~ /^([\/.\w.]+)$/; # The "untainted" file is now in $1 $files = $1; die "Bad filename" unless $files; print<<HTML; <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO +-8859-1"> <title>Upload - File Deleted</title> </head> <body bgcolor="#ffffff"> <form action="upload.cgi" Method="post" ENCTYPE="multipart/form-da +ta"> <P>File(s) Have Been Deleted: <INPUT TYPE="HIDDEN" NAME="page" VALUE="$page"> <br> HTML foreach ($files){ unlink($_); } print<<HTML; <br> <INPUT TYPE="submit" NAME="action" VALUE="Back To Main +"> </FORM> <p></p> <!-- trying to get dir_files to print here --> HTML }

2001-12-03 Edit by Corion : Added missing </CODE> tag.


In reply to Adding and Deleting Upload File name and File by lex2001

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.