Elijah has asked for the wisdom of the Perl Monks concerning the following question:
The problem seems to be that cgi.pm messes with the filehandle to make it more "lightweight/nonusable". I built a simple html form using an input type of of file and a enctype of multipart/form-data. Using the input "file" type browse button to select a file off the local filesystem and submitting the form renders this output in my browser:
Here is the subroutine I have the form send to:Filename => dos_performance.xls Size => 106496 Content-Type: text/html; charset=ISO-8859-1 Undefined subroutine Fh::s +eek at /usr/lib/perl5/site_perl/5.8.6/File/MimeInfo/Magic.pm line 97
It seems that File::MimeInfo::Magic has a problem with the filehandle that is returned by CGI.pm. As you can see I have tried to re-add some of the missing parent objects but this still fails. AM I not doing this correctly? How would one go about checking the mimetype of data in buffer without having to write out a tmp file just to get the mimetype. I am not storing the file on the filesystem, but in a database so the intermediate step if writing the file out would waste cycles being written and then waste cycles having to be deleted.sub upload { my ($obj, $db) = @_; my $project_id = $PTS::QUERY_STRING{'pid'}; my $user_id = $PTS::QUERY_STRING{'uid'}; my $fname = $PTS::QUERY_STRING{'fname'}; my $filehandle = $PTS::CGI->upload('fname'); my $size = -s $filehandle; print $PTS::CGI->header(); print "Filename => $fname\n<br>"; print "Size => $size\n<br>"; push @Fh::ISA, 'IO::Seekable' unless $filehandle->isa('IO::Seekabl +e'); push @Fh::ISA, 'IO::Handle' unless $filehandle->isa('IO::Handle'); print "Mime Type => ".File::MimeInfo::Magic->magic($filehandle)."\ +n<br>"; #show($obj, $db); }
Anyone have any ideas on how to get this working?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI.pm and filehandle woes
by Sidhekin (Priest) on Mar 27, 2007 at 19:12 UTC | |
by Elijah (Hermit) on Mar 27, 2007 at 19:35 UTC | |
by Elijah (Hermit) on Mar 27, 2007 at 19:20 UTC | |
by Sidhekin (Priest) on Mar 27, 2007 at 19:30 UTC | |
by markjugg (Curate) on Jun 22, 2008 at 12:46 UTC | |
|
Re: CGI.pm and filehandle woes
by sgifford (Prior) on Mar 27, 2007 at 19:16 UTC | |
|
Re: CGI.pm and filehandle woes
by Zaxo (Archbishop) on Mar 27, 2007 at 19:24 UTC | |
by Elijah (Hermit) on Mar 27, 2007 at 19:29 UTC |