$final = _upload($localfile,$destination,$filename); if ($final > 0) { #then the file was uploaded successfully! } else { return 'There was an error with the file you supplied, either it was of 0 bytes size or the system failed!
Back'.$final; } #### my $destination = "path"; my $localfile = $q->param('upload_image'); my $filename = $q->param('upload_file'); #### sub _upload { my $localfile = shift; my $totalbytes; my ($bytesread, $buffer); my $num_bytes = 1024; my $destination = shift; my $filename = shift; my $final; my $output_file = $destination . $filename; use CGI::Upload; open (OUTFILE, ">", "$output_file") or die "Couldn't open $output_file for writing"; while ($bytesread = read($localfile, $buffer, $num_bytes)) { $totalbytes += $bytesread; print OUTFILE $buffer; } die "$output_file Read Failure: $!" unless defined($bytesread); unless (defined($totalbytes)) { # $final = "

Error: Could not read file $localfile, or was of zero length"; $final = 0; } else { # $final = "

Done ok, $totalbytes

"; $final = $totalbytes; } close OUTFILE or die "Couldn't Close file $!"; return $final; }