michellem has asked for the wisdom of the Perl Monks concerning the following question:

Hi Fellow Monks,

I have a strange problem with the following code:

my $file= param(UPLOAD_FILE); if (!$file) { graceful_exit("No File!");} my $file_name; my @fname; if ($file =~ m/^[A-Z]+:/) { # its a full filename (@fname) = split(/\\/,$file); $file_name = $fname[$#fname]; } print "Filename:$file, $file_name, $#fname\n"; if ($#fname < 0) {$file_name = $file;} my $content_type = uploadInfo($file_name)->{'Content-Type'}; my $file_handle = upload(UPLOAD_FILE); open FILE, "<".FILESHARE_DIR or graceful_exit("Can't read director +y file"); chomp(my $directory = <FILE>); sysopen (OUTFILE, "$directory/$file", O_WRONLY | O_CREAT) or grace +ful_exit("Can't create file!");
In netscape and mozilla, this code works just fine - the file uploads happily. In IE 5 and 5.5 it barfs, with the following error:

"Can't use an undefined value as a HASH reference at ... line ..." which points to this line: my $content_type = uploadInfo($file_name)->{'Content-Type'};

Ideas? Suggestions?Thanks!
.Michelle

Replies are listed 'Best First'.
Re: IE vs Netscape problems with Uploading
by ajt (Prior) on Dec 21, 2001 at 03:15 UTC
    michellem,

    Assuming things were uploaded okay, which may not always be the case....

    Ah... According to Lincoln not all clients return a MIME type, so the result your getting must be because IE doesn't bother, so there is no media type set.

    When a file is uploaded the browser usually sends along some information along with it in the format of headers. The information usually includes the MIME content type. Future browsers may send other information as well...

    I've had lots of fun recently with upload scripts, sometimes things work on IE, sometimes on Mozilla and sometimes on Opera - if only they would all play the same way. end rant..

    If you need to know the meida-type you can use the LWP::MediaTypes (which just looks at the extension really), or the File::MMagic which looks for magic numbers in the file and makes a good guess.

    Hope this is helpful...

Re: IE vs Netscape problems with Uploading
by tradez (Pilgrim) on Dec 21, 2001 at 03:01 UTC
    try to
    warn "Testval ->$file_name \n";
    right before that line. Check the apache logs and see if you have a value there. This might be a dumb question, but if you haven't done it yet, would be the first thing I do. tradez
Re: IE vs Netscape problems with Uploading
by cfreak (Chaplain) on Dec 21, 2001 at 20:28 UTC
    You also might want to check if your html <form> tag has enctype="multipart/form-data". I've gotten this same error before when mine didn't and it can cause weird stuff with different browsers.

    Hope that helps
    Chris