[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Undefined hash reference error using CGI's uploadInfo()

Posted on 2006-05-10
1
Medium Priority
?
362 Views
Last Modified: 2011-09-20
Hi
I get an "undefined hash reference error" when I use uploadInfo() in this code. The keys of %vars are  
"input type = file[]":

1 my %vars = $cg->Vars;
2 while(($key,$value) = each %vars)
3 {
4    my $fh = $cg->upload($key);
5    $file_name = $cg->param($key);
6    $file_type = uploadInfo($file_name)->{'Content-Type'};
7 }

Line 6 gives me the error.

Any ideas?
0
Comment
Question by:tr5
1 Comment
 
LVL 28

Accepted Solution

by:
FishMonger earned 1000 total points
ID: 16648365
If you print the keys to the %var hash, you should find at least 1 of them will not a filename to be uploaded; it'll be the name of the submit button.  So when you do
$file_type = uploadInfo($file_name)->{'Content-Type'};
on that key, $file_type will be undefined.

Also, the $fh could be undefined for the following reason (taken from the cgi cpan doc),

There are occasionally problems involving parsing the uploaded file. This usually happens when the user presses "Stop" before the upload is finished. In this case, CGI.pm will return undef for the name of the uploaded file and set cgi_error() to the string "400 Bad request (malformed multipart POST)". This error message is designed so that you can incorporate it into a status code to be sent to the browser. Example:

   $file = upload('uploaded_file');
   if (!$file && cgi_error) {
      print header(-status=>cgi_error);
      exit 0;
   }
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question