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?
In reply to CGI.pm and filehandle woes by Elijah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |