How can I check the MIME type of an uploaded file using Perl CGI?
I'm trying to get the MIME type of an <input type="file" />
e开发者_StackOverflowlement using Perl, but without actually examining the contents of the file itself, In other words, just using the HTTP headers.
I have only been able to get the "multipart/form-type" Content-Type value, but my understanding is that each element will get its own MIME Type?
How can I see the sub-MIME types using Perl?
I assume that you are using CGI.pm to do this. If you are using the OO interface to CGI you can do something like this.
use strict;
use warnings;
use CGI;
my $cgi = CGI->new;
my $filename = $cgi->param('upload_param_name');
my $mimetype = $cgi->uploadInfo($filename)->{'Content-Type'};
If you are using the procedural interface, the equivalent would be:
use strict;
use warnings;
use CGI qw/param uploadInfo/;
my $filename = param('upload_param_name');
my $mimetype = uploadInfo($filename)->{'Content-Type'};
精彩评论