Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload File to server creating 0-size file...

Status
Not open for further replies.

PerlIsGood

Programmer
Jan 24, 2002
154
US
I've read through and used most of the code from goBoating's faq219-406. I've also read through CGI.pm on file uploading - still can't get this bloody thing to work. It will create the file on the server, but with 0 size - seems to me read isn't doing what it's supposed to. Anyway, if anyone can point out the flaw in my code I'd be greatly appreciative.

Code:
@file = split /\\/, $query{'fileID'};
$new_dir = "../_files/$query{'game'}/$query{'section'}/";
$new_file = $file[$#file];

sub process_success {
  my ( $bytes_read, $sum_bytes, $buffer );
  open OPF, "> $new_dir/$new_file" or die "Could not create $new_file on the remote server: $!";
  print $q->header;
  print "Uploading '$query{'fileID'}' to the server...!";
    while ( $bytes_read = read ($query{'fileID'}, $buffer, 1024) ) {
      print OPF $buffer;
      $sum_bytes += $bytes_read;
      if ( $sum_bytes > 27000 ) {
        close OPF;
        unlink "$new_dir/$new_file";
        $err_count++;
        last;
      }
    }
  close OPF;
  print $q->end_html;
}

I've tried every file-type I could get my hands on, all with the same results. All error trapping works prior to hitting this sub, and print de-bugging %query checks out (all data in proper format/expected format) ... I'm confused... Notorious P.I.G.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top