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 updates 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 spaces $longfile =~ s/^(.*[\/\\:])*([^\/\\:]+)$/$2/; # remove path if ($longfile !~ /\./) { $fileerror = '2'; last; } $longfile =~ s/\.(?=.*\.)//g; # substitute 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 *$tempfile* 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 designated directory $dir $!"); my @files = grep /^$self->{'DOCID'}[2]$doc/, readdir DIRH; @files = map ("$dir/$_", @files); closedir DIRH; unlink @files or Util->showError("oops cant unlink your chosen files @files $!"); } $self->{$doc}[2] = ''; } } umask($umm); return $fileerror; }