get mime type by file extension

The place for "I can't figure out how to..." questions.
Post Reply
WaldoMonster
getID3() contributor
Posts: 112
Joined: Mon Apr 01, 2002 12:20 am
Location: Netherlands
Contact:

get mime type by file extension

Post by WaldoMonster » Thu Jan 11, 2007 3:09 pm

Is it possible to get the mime type when you only know the file extension?
If it is possible can you give me an example?

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Sat Jan 13, 2007 2:23 am

You can take a guess, and presume that the file extension is correct. It would just be a very simple lookup table.

WaldoMonster
getID3() contributor
Posts: 112
Joined: Mon Apr 01, 2002 12:20 am
Location: Netherlands
Contact:

Post by WaldoMonster » Sat Jan 13, 2007 10:39 am

Is the guessing possible with getID3()?
Maybe something like:

Code: Select all

<?php
require_once('getid3/getid3.php');
define('GETID3_HELPERAPPSDIR', 'no_helper_apps_needed');

$getID3 = new getID3;
$getID3->analyze('dummy.mp3');

if (isset($getID3->info['mime_type'])) echo $getID3->info['mime_type'];
?>
Than I don't have to make a lookup table what already is defined in getID3().

James Heinrich
getID3() v1 developer
Posts: 1476
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Post by James Heinrich » Sat Jan 13, 2007 1:54 pm

If you analyze the file with getID3, then it's not guessing anymore, it's knowing with reasonable certainty. getID3 generally ignores the filename completely and analyzes the content to determine filetype.

If you want an extension-based MIME type lookup, you just need a lookup table, based on some data like this:
http://en.wikipedia.org/wiki/Internet_m ... edia_types

WaldoMonster
getID3() contributor
Posts: 112
Joined: Mon Apr 01, 2002 12:20 am
Location: Netherlands
Contact:

Post by WaldoMonster » Sun Jan 14, 2007 1:34 pm

I hoped I could get ride of my lookup table.
For source streaming I will use GetID3() to get the mime type.
Only for transcode-streaming I will make a short lookup table as you mentioned.

Thanks,

Willem

Post Reply