lex2001 has asked for the wisdom of the Perl Monks concerning the following question:
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:my %test = qw( @song_titles, @song_files );
#### # 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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adding and Deleting Upload File name and File
by larryk (Friar) on Dec 03, 2001 at 14:34 UTC | |
by blakem (Monsignor) on Dec 03, 2001 at 16:28 UTC | |
by larryk (Friar) on Dec 03, 2001 at 17:37 UTC | |
by blakem (Monsignor) on Dec 04, 2001 at 00:43 UTC | |
by lex2001 (Sexton) on Dec 05, 2001 at 14:24 UTC | |
by larryk (Friar) on Dec 05, 2001 at 19:13 UTC | |
| |
|
Re: Adding and Deleting Upload File name and File
by andye (Curate) on Dec 03, 2001 at 16:42 UTC |