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:


use to call
$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; }

Destiantion is obviosuly
my $destination = "path"; my $localfile = $q->param('upload_image'); my $filename = $q->param('upload_file');

In your case swap upload_image and upload_file with uploadfile_0, i have to as my form gives the option to rename the file (just another input field). This code snippet (above) should go above the 'calling' bit
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; }
Barry Carlyon barry@barrycarlyon.co.uk

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.