Fun with CGI.pm & upload & Content-Type
I was working with the file upload yolk of CGI.pm, and more accurately the code after the following comments in the documents.
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 (such as modification date and size). To retrieve this information, call uploadInfo(). It returns a reference to an associative array containing all the document headers.
The docs tell describe getting the MIME type like so.
$filename = param('uploaded_file');
$type = uploadInfo($filename)->{'Content-Type'};
This works fine in Mozilla browsers but the param('uploaded_file') described above is garbage in IE, IE appears to pass the full path to the file on the users operating system as described here.
Different browsers will return slightly different things for the name. Some browsers return the filename only. Others return the full path to the file, using the path conventions of the user's machine. Regardless, the name returned is always the name of the file on the user's machine, and is unrelated to the name of the temporary file that CGI.pm creates during upload spooling.
So in order to get the correct MIME TYPE regardless of the browser I had to call uploadInfo on an open filehandle like so.
my $up_handle = $q->upload("bin_file");
$type = $q->uploadInfo($up_handle)->{'Content-Type'};
Maybe I have read the documentation wrong but if I interpret it as it appears to me, the docs seem to be wrong.