perlquestion
c
In the [http://search.cpan.org/doc/LDS/CGI.pm-2.78/CGI.pm|CGI.pm] documentation, it shows the following example:<p>
<code>
$file = $query->upload('uploaded_file');
if (!$file && $query->cgi_error) {
print $query->header(-status=>$query->cgi_error);
exit 0;
}
</code><p>
This lets you do a check on the MIME type of a file being uploaded, provided that the browser passes this type of info for the file. I've tried using this syntax with both Netscape 4.7 and IE 5.5, but neither seems to pass the information. With fatalstobrowser enabled, I receive:<p>
<code>
Can't use an undefined value as a HASH reference at /path/to/search-howto.cgi line 185.
</code><p>
My code verbatim, is:<p>
<font size=-1>
<code>
sub upload_image {
## pull the file in a variable
my $fh = $query->upload('upload');
## determine the file type via the headers
my $type = $query->uploadInfo($fh)->{'Content-Type'};
## take action based on type
if ($type eq 'text/html') {
## hash of file names to write to
my %destination = ( 'match' => "match.html", 'no_match' => "no_match.html");
## open the file to be written
open(HTML, ">/www/$destination{$formdata{filename}}")
or die "Cant open HTML file for writing : $!\n";
## if file is determined to be text/html write contents to appropriate location
while(<$fh>) {
print HTML "$_\n";
}
close(HTML);
## otherwise set error for later notification within html
} else {
$error = "on";
}
}
</code>
</font><p>
When I remove the uploadInfo line, the file gets uploaded properly, however its not worth it for me to remove this line. Can someone point out what I am missing?<p>
-[c]