in reply to Finding out mime types...
Since you seem to be running Windows you might ask the system what is the content type according to it:
(If the code doesn't work for you it might be because I tested it with Win32::Registry2 installed.)use Win32::Registry; use strict; { my %cache; sub GetContentType { my $ext = shift(); # well it's a filename at this point for ($ext) { s/^.*\.//; # now we extract the extension $_ = lc $_; } return $cache{$ext} if exists $cache{$ext}; my $key; $HKCR->Open('.'.$ext, $key) or return; my ($type, $value); $key->QueryValueEx('Content Type', $type, $value) or return; $cache{$ext} = $value; return $value; } } print "Foo.exe: " . GetContentType('Foo.exe') . "\n"; print "Foo.gif: " . GetContentType('Foo.gif') . "\n"; print "bar.exe: " . GetContentType('bar.exe') . "\n";
Jenda
Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.
-- Rick Osborne
Edit by castaway: Closed small tag in signature
|
|---|