> 
> Hi all 
> 
> I am trying to find the file type of a file being uploaded
> 
> im using CGI.pm for uploading the file
> 
> here is the code 
> 
> 
> **********************************************************
> 
> $filename1 = $q->param("test_file");
> my $uploadFileHandle = $q->upload("test_file");
> my $test;
> 
> 
> $type = $q->uploadInfo($filename1)->{'Content-Type'};

I think (read: CGI.pm is incredibly complex and hard to follow).

You are passing the $filename1 which is (depending on the browser) the
filename provided by the client. You should be passing the opened handle
to 'uploadInfo', aka,

$type = $q->uploadInfo($uploadFileHandle)->{'Content-Type'};

Now having said that, the docs on the CGI module seem to be wrong. The
source takes the filename, but I believe it is the 'local' filename,
which is not what is returned by 'param' because it returns the name
provided in the Content-Disposition of the multipart header for that
part (at least I think).  Either way uploadInfo attempts to index into
the object using the 'fileno' which means it must be either the open
handle or the local filename, never the remote or client provided.

The weird thing is that the filename provided by the client is stored
into the parameter list, but then within the object itself the local
filename is stored, but to my knowledge there is no way to access it.

Very strange indeed.

> 
> 
> the above particular statement gives me an error 
> 
> Can't use an undefined value as a HASH reference
> 

This just means that uploadInfo is returning undef because it isn't
finding the filename, for the reasons stated above.  

> 
> i recollect using the same code and it worked earlier 
> but that was on a different version of CGI.pm(not sure which)
> so i suspect the version of CGI.pm
> 

The switch to using the fileno of the handle/local file could have
definitely been recent, as I think it may be in place to handle multiple
 file uploads.

> what am i doing wrong here also 
> how to find the version of an installed module in the perl 
> lib

perl -M<module> -e 'print $<module>::VERSION'

Should work for most modules on CPAN, at least the ones that follow the
conventions.

perl -MCGI -e 'print $CGI::VERSION'

Can one of the gurus take a look at the CGI module to see if my
understanding of it is correct.  I can post a doc bug report to Lincoln
Stein if someone else can confirm I am not off my rocker.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to