here you go
You can decide where file is to be saved. Sample below save file in directory c:/upload (make sure to create this directory before you test the script)
#!c:/perl/bin/perl.exe
use CGI qw/:standard/;
print header;
if(param) {
save_file();
} else {
print_form();
}
sub print_form {
print start_html('File upload'),
start_multipart_form(),
'File:',filefield(-name=>'file',-size=>60),br,
submit(-label=>'Upload'),
end_form,
end_html;
}
sub save_file {
my $file = param('file');
if (!$file) {
print start_html,"file not found",end_html;
exit;
}
if($file=~m!([^/\\]+$)!) {
my $savefile="c:/upload/$1";
if(open(OUTFILE, ">$savefile")) {
binmode(OUTFILE);
while (my $bytesread = read($file, my $buffer, 16384)) {
print OUTFILE $buffer;
}
close (OUTFILE);
print start_html,"file upload complete, saved as $savefile",end_html;
} else {
print start_html,"error opening file $savefile: $!",end_html;
}
}
}
-----------------------------------------------------------