uploadInfo method going wonky

Earle Martin perl at
Thu Jan 4 12:11:25 GMT 2007

Anyone encountered this before? (Already asked of IRC, apologies if
you've seen it.)


use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = CGI->new;

my $params = { 'ImageFile' => $q->param('ImageFile') };

my $image = $q->upload('ImageFile');

my $upload_info = $q->uploadInfo($params->{'ImageFile'});

my $bollocks = "File name: $params->{'ImageFile'}\n";
$bollocks .= "Upload object: " . Dumper $image;
$bollocks .= "Upload info: " . Dumper $upload_info;
die $bollocks;


Dies with:

File name: vermeer - girl with a pearl earring.jpg
Upload object: $VAR1 = bless( \*{'Fh::fh00001vermeer - girl with a
pearl earring.jpg'}, 'Fh' );
Upload info: $VAR1 = undef;


So for some reason, as far as I can tell, although $q has got the
upload, something is going wrong when I try and call CGI::uploadInfo()
with the upload's name. Strangely, this same method was working for me
earlier this morning, although frustratingly I'm unable to find what
changed to cause this. (That'll teach me to commit more often.)

I've had suggestions of using CGI::Upload, but that merely wraps
File::MMagic, and I've found that File::MMagic incorrectly[1]
identifies an upload stream as "text/plain" every time (although
producing the correct result for a file on disk).

Generally speaking, as the uploaded file is passed elsewhere pending
successful checks of one kind or another and never actually written to
disk, I'm trying to avoid the need to write out to a temporary file
and check the file type. I'm happy to trust the result of

[1] Unless there is some special reason I'm unaware of.

Earle Martin

More information about the mailing list