Brauche die Datei magic.mime für eine Funktion.
Wo kann man die Datei saugen?
cheers
PHP-Code:
/*
Magic mime file interpreter
Copyright (c) 2004 by Phillip Berndt
Version 1.0
*/
function mime_content_type($file)
{
static $mimeData;
if(!isset($mimeData))
{
$mimeFile = file('./magic.mime');
foreach($mimeFile as $mimeLine)
if($mimeLine[0] != '#' && trim($mimeLine))
{
if(preg_match('/^(\S+?)\s+(\S+?)\s+(\S+)(\s+(.+?))?$/si', $mimeLine, $regex_mimeDataSet))
{
$mimeDataSet['offset'] = str_replace('>', '', $regex_mimeDataSet[1]);
$indicator = $regex_mimeDataSet[3];
switch($regex_mimeDataSet[2])
{
case 'string':
$indicator = str_replace('\ ', ' ', $indicator);
$indicator = str_replace('\<', '<', $indicator);
$indicator = str_replace('\>', '>', $indicator);
$indicator = str_replace('\r', "\r", $indicator);
$indicator = str_replace('\n', "\n", $indicator);
$indicator = preg_replace('/\\\\([0-9]{3})/e', 'chr($1);', $indicator);
break;
case 'byte':
$indicator = pack('c', @eval('return '.$indicator.';'));
break;
case 'short':
$indicator = pack('s', @eval('return '.$indicator.';'));
break;
case 'beshort':
$indicator = pack('n', @eval('return '.$indicator.';'));
break;
case 'leshort':
$indicator = pack('v', @eval('return '.$indicator.';'));
break;
case 'belong':
$indicator = pack('N', @eval('return '.$indicator.';'));
break;
case 'lelong':
$indicator = pack('V', @eval('return '.$indicator.';'));
break;
case 'long':
$indicator = pack('l', @eval('return '.$indicator.';'));
break;
}
$mimeDataSet['indicator'] = $indicator;
$mimeDataSet['mime'] = str_replace("\r", '', $regex_mimeDataSet[5]);
$mimeData[] = $mimeDataSet;
}
}
}
$file_content = file_get_contents($file);
$retVal = 'application/x-object';
foreach($mimeData as $key => $mimeTest)
{
$testStr = substr($file_content, $mimeTest['offset'], strlen($mimeTest['indicator']));
if($testStr == $mimeTest['indicator'])
{
$mimeType = $mimeTest['mime'];
if($mimeType == '')
{
while($mimeType == '')
$mimeType = $mimeData[++$key]['mime'];
}
$retVal = $mimeType;
}
}
return $retVal;
}
cheers
Kommentar