in reply to Re: IE vs. Firefox : Can't use an undefined value as a HASH reference error
in thread IE vs. Firefox : Can't use an undefined value as a HASH reference error

I'm playing my novice card here, but when you ask for the source of uploadInfo, what are you asking for? The code for that function? uploadInfo is from CGI.pm, so you want the source from the CGI module?

In the form, the field for the file to upload is
<input type="FILE" name="filename">
The script then gets the filename:
$File_Name = Get_File_Name(param('filename')); sub Get_File_Name{ if($ENV{HTTP_USER_AGENT} =~ /win/i){ fileparse_set_fstype("MSWin32"); #changed from MSDOS to try a +nd fix the A:\ problem } elsif($ENV{HTTP_USER_AGENT} =~ /mac/i) { fileparse_set_fstype("MacOS"); } my $full_name = shift; $full_name = basename($full_name); $full_name =~ s!\s!\_!g; # Replace whitespace with _ return($full_name); }
and calls sub to store the file ($Directory is a path and is already defined):
storeFiles($File_Name, $Directory); #stores uploaded files sub storeFiles{ my($filename, $directory) = @_; #name subroutine variables my $data; my $mime = uploadInfo($filename)->{'Content-Type'}; open (STORAGE, ">$directory/$filename") or die "Error: $directory/ +$filename: $!\n"; if($mime !~ /text/){ binmode ($filename); binmode (STORAGE); } while( read($filename, $data, 1024) ){ print STORAGE $data;} close STORAGE; }
I'm guessing the content-type isn't being passed correctly from IE, but I'm not what to change since I've already set the form type as a multipart-form.

Replies are listed 'Best First'.
Re^3: IE vs. Firefox : Can't use an undefined value as a HASH reference error
by Roy Johnson (Monsignor) on Feb 24, 2005 at 19:04 UTC
    uploadInfo is from CGI.pm, so you want the source from the CGI module?
    That would be the relevant code, yes. Not being a frequent CGI programmer, myself, I didn't recognize that it was a CGI function. So here's the source:
    sub uploadInfo { my($self,$filename) = self_or_default(@_); return $self->{'.tmpfiles'}->{$filename}->{info}; }
    It's a method, and you're calling it as an ordinary sub.

    Update: as dragonchild points out, that's not the problem. So the critical issue looks like: what is the value of $filename? It may require some exploration and dumping of data to see what value it should have in order to work.


    Caution: Contents may have been coded under pressure.
      Nope. Every function in CGI can be called as either a function or a method. That's what the self_or_default() function does.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Thanks. I'll look into the object method. I still don't understand why the script works when called from a form in Firefox but not in IE. Because it seems that uploadInfo works in one case but not another.
        My object method suggestion was wrong. However, you can dump the data structure to see why it (apparently) isn't finding the information:
        my $def_obj = CGI::self_or_default($filename); use Data::Dumper; print Dumper $def_obj->{'.tmpfiles'};

        Caution: Contents may have been coded under pressure.