Click to See Complete Forum and Search --> : PLEASE help with file uploads! Simple request for n00b!


Super Sonic
05-10-2004, 05:14 PM
Man, I'm going through heck right now. I have a total of 5 upload slots on a single form. I would like for each to upload a file and save that file into a particular user-specified directory.
I went here:
http://webdesign.about.com/library/weekly/aa030899.htm

But I soon found out that that was too broad and not descriptive enough for me to follow nor work into my preexisting script.

The script I'm making is for reviewing video games. The user selects what type of game it is(Example: Sonic, Mario) from a select list. Next the user enters the name of the game (text box). When I upload the image files (screenshots for the game being reviewed), I would like for them to go to $TYPE/$NAME (Example: Sonic/Sonic3) directory. That way all of the images will be sent to the same folder and be organized. BUT I have a total of five available slots for uploading images. Could you guys show me how to write a little script that accomplishes what I need. PLEASE, I'm begging of you.
I've started on this project not too long ago where a user can make a full professional review by just simply filling out a form. The CGI script then makes an .html file with the users input formatted in a perfect standard way. I have everything done ACCEPT for file uploads. PLEASE HELP!

silent11
05-12-2004, 10:23 AM
some modules here (http://search.cpan.org/search?query=CGI+Upload&mode=all) may help you on your way.

Super Sonic
05-12-2004, 08:25 PM
Okay. I got a single file uploaded. Then I tried to do it with five and it didn't work anymore. Here is what I've got:

Use CGI;
Use Scrict;
my $query = new CGI;
my $FILENAME1 = $query->param('shot1');
my $FILENAME2 = $query->param('shot2');
my $FILENAME3 = $query->param('shot3');
my $FILENAME4 = $query->param('shot4');
my $FILENAME5 = $query->param('shot5');
my @UPLOADS = ($FILENAME1, $FILENAME2, $FILENAME3, $FILENAME4, $FILENAME5);
foreach $_(@UPLOADS) {
if ($_ =~ /.*[\/\\](.*)/) {
$out_filename = $1;
}
else {
$out_filename = $_;
}
open (OUTFILE, ">$out_filename");
while ($bytesread = read ($_, $buffer, 1024)) {
print OUTFILE $buffer;
}
close $_;
Close OUTFILE;
}