in reply to Uploading via HTML/Using CGI.pm

In addition to the links above from t0mas, the way I have used in the past is via cgi->tmpFileName and using File::Copy,

A subroutine example is below, msg me if you cant work out which bits might be useful.

P.S I have a suspicion setting the umask to 000 might not be a good thing but this sub is renaming the files...

sub storeFiles { my $self = shift; my $cgi = shift; my $mode = shift; # going to be insert or update my $fileerror = '0'; my @filecols = ('DOC_1', 'DOC_2', 'IMG_1', 'IMG_2', 'IMG_3', 'IMG_ +4'); my $umm = umask(000); foreach my $doc (@filecols) { if ($cgi->param($doc)) { # if insert this is an add, else a replace action for upda +tes my $longfile = $cgi->param($doc); my $tempfile = $cgi->tmpFileName($longfile); my $size = -s $tempfile; if (($size < 1) || ($size > 2000000)) { $fileerror = '1'; last; } $longfile =~ s/ //g; # strip sp +aces $longfile =~ s/^(.*[\/\\:])*([^\/\\:]+)$/$2/; # remove p +ath if ($longfile !~ /\./) { $fileerror = '2'; last; } $longfile =~ s/\.(?=.*\.)//g; # substitu +te all but last dot (courtesy of L.Rosler) my ($f, $ext) = split /\./, $longfile; if (!$self->_isValidFile($doc, $ext)) { $fileerror = '3'; last; } my $newfile = $DATA_DIR . $self->{'PAGE'}[2] . "/" . $self +->{'DOCID'}[2] . $doc . "." . $ext; eval { copy ($tempfile, $newfile) or die "cant copy temp *$te +mpfile* to new *$newfile* $! \n longfile is $longfile"; }; if ($@) { $fileerror = '4'; last; } else { $self->{$doc}[2] = $self->{'DOCID'}[2] . $doc . "." . +$ext; } } elsif ($cgi->param("exists$doc")) { $self->{$doc}[2] = $cgi->param("exists$doc"); } else { $self->{$doc}[2] = ''; } if (($cgi->param("chk$doc")) && (!$cgi->param($doc))) { # unlink file if update checkbox is checked my $page = $self->{'PAGE'}[2]; if (($page == 22) || ($page == 26) || ($page == 27)) { my $dir = "../data/$page"; opendir (DIRH, $dir) or Util->showError("Can't Open de +signated directory $dir $!"); my @files = grep /^$self->{'DOCID'}[2]$doc/, readdir D +IRH; @files = map ("$dir/$_", @files); closedir DIRH; unlink @files or Util->showError("oops cant unlink you +r chosen files @files $!"); } $self->{$doc}[2] = ''; } } umask($umm); return $fileerror; }