I had this problem, there is a node somewhere on perl monks by me, I think you forgetting to set up a buffer so I'll just going to dump the code Im currently using:
$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!<br /> <a href="javascript: +history.go(-1);" >Back</a>'.$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_fi +le 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 = "<p>Error: Could not read file $localfile, or was of zer +o length"; $final = 0; } else { # $final = "<p>Done ok, $totalbytes</p>"; $final = $totalbytes; } close OUTFILE or die "Couldn't Close file $!"; return $final; }
In reply to Re: Uploading Files with CGI.pm results in 0 byte files
by barrycarlyon
in thread Uploading Files with CGI.pm results in 0 byte files
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |