public static function getMimeType($path, $ext = false)
    {
        $mime_types = self::getMimeTypeList();
        
        if (false == $ext){
        	$ext = pathinfo($path, PATHINFO_EXTENSION);
        	
        	if (array_key_exists($ext, $mime_types)) {
        		$mimetype =  $mime_types[$ext];
        	} 
        	else {
        		$mimetype = '';
        	}

            if (!in_array($ext, array('css', 'ogg', 'mp3'))) {
        		if  (file_exists($path)) {
        			if (function_exists('finfo_open')) {
        				$finfo = finfo_open(FILEINFO_MIME);
        				$mimetype = finfo_file($finfo, $path);
        				finfo_close($finfo);
        			}
        			else if (function_exists('mime_content_type')) {
        				$mimetype = mime_content_type($path);
        			}
        			if (!empty($mimetype)) {
        				if (preg_match("/; charset/", $mimetype)) {
        					$mimetypeInfos = explode(';', $mimetype);
        					$mimetype = $mimetypeInfos[0];
        				}
        			}
        		}
        	}
        }
        else{
        	// find out the mime-type from the extension of the file.
        	$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        	if (array_key_exists($ext, $mime_types)){
        		$mimetype = $mime_types[$ext];
        	}
        }
		
        // If no mime-type found ...
        if (empty($mimetype)) {
        	$mimetype =  'application/octet-stream';
        }

		return (string) $mimetype;
    }
public static function getMimeType($path, $ext = false)
    {
        $mime_types = self::getMimeTypeList();
        
        if (false == $ext){
        	$ext = pathinfo($path, PATHINFO_EXTENSION);
        	
        	if (array_key_exists($ext, $mime_types)) {
        		$mimetype =  $mime_types[$ext];
        	} 
        	else {
        		$mimetype = '';
        	}

            if (!in_array($ext, array('css', 'ogg', 'mp3'))) {
        		if  (file_exists($path)) {
        			if (function_exists('finfo_open')) {
        				$finfo = finfo_open(FILEINFO_MIME);
        				$mimetype = finfo_file($finfo, $path);
        				finfo_close($finfo);
        			}
        			else if (function_exists('mime_content_type')) {
        				$mimetype = mime_content_type($path);
        			}
        			if (!empty($mimetype)) {
        				if (preg_match("/; charset/", $mimetype)) {
        					$mimetypeInfos = explode(';', $mimetype);
        					$mimetype = $mimetypeInfos[0];
        				}
        			}
        		}
        	}
        }
        else{
        	// find out the mime-type from the extension of the file.
        	$ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
        	if (array_key_exists($ext, $mime_types)){
        		$mimetype = $mime_types[$ext];
        	}
        }
		
        // If no mime-type found ...
        if (empty($mimetype)) {
        	$mimetype =  'application/octet-stream';
        }

		return (string) $mimetype;
    }
public static function getMimeType ( $ path , $ ext = false ) { $ mime_types = self :: getMimeTypeList ( ) ; if ( false == $ ext ) { $ ext = pathinfo ( $ path , PATHINFO_EXTENSION ) ; if ( array_key_exists ( $ ext , $ mime_types ) ) { $ mimetype = $ mime_types [ $ ext ] ; } else { $ mimetype = '' ; } if ( ! in_array ( $ ext , array ( 'css' , 'ogg' , 'mp3' ) ) ) { if ( file_exists ( $ path ) ) { if ( function_exists ( 'finfo_open' ) ) { $ finfo = finfo_open ( FILEINFO_MIME ) ; $ mimetype = finfo_file ( $ finfo , $ path ) ; finfo_close ( $ finfo ) ; } else if ( function_exists ( 'mime_content_type' ) ) { $ mimetype = mime_content_type ( $ path ) ; } if ( ! empty ( $ mimetype ) ) { if ( preg_match ( "/; charset/" , $ mimetype ) ) { $ mimetypeInfos = explode ( ';' , $ mimetype ) ; $ mimetype = $ mimetypeInfos [ 0 ] ; } } } } } else { // find out the mime-type from the extension of the file. $ ext = strtolower ( pathinfo ( $ path , PATHINFO_EXTENSION ) ) ; if ( array_key_exists ( $ ext , $ mime_types ) ) { $ mimetype = $ mime_types [ $ ext ] ; } } // If no mime-type found ... if ( empty ( $ mimetype ) ) { $ mimetype = 'application/octet-stream' ; } return ( string ) $ mimetype ; }
Get the mime-type of the file in parameter.
different methods are used regarding the configuration of the server.

@author Lionel Lecaque, <lionel@taotesting.com>
@param  string $path
@param  boolean $ext If set to true, the extension of the file will be used to retrieve the mime-type. If now extension can be found, 'text/plain' is returned by the method.
@return string The associated mime-type.
Get the mime - type of the file in parameter . different methods are used regarding the configuration of the server .