[Cedarvalley] upload problem

Aaron Thompson thompson at math-cs.cns.uni.edu
Thu Dec 11 10:54:13 CST 2003


I'm using CGI to upload a file... the file box is 'upload-me' and the code
below works for Netscape 4, but not Mozilla 1.5 or IE 6.  Anyone have
experience with this and can point me in the right direction?

Error message (from apache error log):
 Use of uninitialized value in <HANDLE> at /home/httpd/photos/admin/index.cgi line 59.
 readline() on unopened filehandle at /home/httpd/photos/admin/index.cgi line 59.


the offending code:
---<snip>---
use CGI;
...

$query = new CGI:
...

######################################################################
sub upload_file{
  my $overwrite = "0"; #overwrite files on upload (yes = 1, no = 0)
  my %valid_mime = ("zip" => "1");
  my $length = 0;
  my $file = $query->param("upload-me");
  my $local_file_name = "";
  my $uploadFH; 
  my $mime;
  my $save_flag;

  $file =~ s/.*[\/\\](.*)/$1/;
  if($file =~ /.*[\.](.*)/){$mime = $1;}#fi
  $local_file_name = $tmp_dir . "/" .$file;
  print "<p>File Upload...<br>This may take some time, please wait...</p>";
  print "<p>Attempting to upload: $file</p>";
  if ($valid_mime{$mime}){
    $save_flag = 1;
    if(! $overwrite){if( -e $local_file_name ){$save_flag = 0;}}#fi
    if($save_flag){
      $uploadFH = $query->upload("upload-me");
      open UPLOADFILE, ">$local_file_name" or
        html_die("Could not open $local_file_name for writing!");
        binmode UPLOADFILE;
        while ( <$uploadFH> ){
          print UPLOADFILE;
          $length += length($_);
        }#elihw
      close UPLOADFILE;
      print "<p><b>$file</b> of size <b>$length bytes</b> was uploaded.</p>";
    }else{
      print "<p><b>$file</b> already exists on the server - not uploaded. </p>";
    }#fi
  }
  else{
    print "<p>File not saved... unallowed file time: $mime</p>";
  }#fi
}

---<snip>---

Thanks for your help.

@


-- 
Aaron Thompson   Unix Systems Administrator, College of Natural Science
University of Northern Iowa                      Cedar Falls, IA  50614

"Because as we know, there are known knowns, there are things we know we
know. We also know there are known unknowns; that is to say we know there are
some things we do not know. But there are also unknown unknowns - the ones we
don't know we don't know." - Donald Rumsfeld



More information about the Cedarvalley mailing list