$max_num_files ||= 1; $Photo_Dir ||= $ENV{'DOCUMENT_ROOT'}; undef @bad_extensions if @good_extensions; for(my $a = 1; $a <= $max_num_files; $a++) { my $req = new CGI; ... #### use strict; use CGI; my $req = new CGI; foreach my $type ( qw/P T/ ) # 'P' for Photo, 'T' for Thumbnail { my $indx = 0; while ( 1 ) # we'll exit when $indx gets high enough { my $paramName = sprintf( "%s_FILE%d", $type, ++$indx ); last unless ( $req->param( $paramName )); my $outname = my $inname = $req->param( $paramName ); $outname =~ s/^.*(\\|\/)//; # remove leading path $outname =~ s/ +/\_/g; # don't want spaces $outname =~ s/\"//g; # don't want quotes $outname = "th_$outname" if ( $type eq "T" ); # removed long portion that depended on @good_extensions and/or # @bad_extensions having contents : no evidence that they ever did # removed long portion that depended on $auto_rename having a value of # 1 or 2 and checking whether "$Photo_Dir/$outname" already exists : # no evidence that $auto_rename is ever non-zero # ( I think the original posted code forgot to open the input file ) my $insize = ( -s $inname ); ( $insize && open( INFILE, $inname )) or next; if ( open( OUTFILE, ">$ENV{DOCUMENT_ROOT}/$outname")) { my $outsize = 0; while ( my $nr = sysread( INFILE, my $buffer, 1024 )) { my $nw = syswrite( OUTFILE, $buffer ); last if ( $nr != $nw ); $outsize += $nw; } close OUTFILE; if ( $outsize != $insize ) { last; # might want to report this somehow... } # removed long portion that depended on $max_size being non-zero : # no evidence that it ever was } close INFILE; } }