public function getMimeType($file)
    {
        if (!empty($file)) {
            // in PHP 5.3 we can use 'finfo'
            if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime_type = finfo_file($finfo, $file);
                finfo_close($finfo);
            } else {
                // A few mimetypes to "guess" using the file extension.
                $mimetypes = array(
                    'txt'   => 'text/plain',
                    'csv'   => 'text/csv',
                    'pdf'   => 'application/pdf',
                    'doc'   => 'application/msword',
                    'docx'  => 'application/msword',
                    'xls'   => 'application/vnd.ms-excel',
                    'ppt'   => 'application/vnd.ms-powerpoint',
                    'eps'   => 'application/postscript',
                    'zip'   => 'application/zip',
                    'gif'   => 'image/gif',
                    'jpg'   => 'image/jpeg',
                    'jpeg'  => 'image/jpeg',
                    'png'   => 'image/png',
                    'mp3'   => 'audio/mpeg',
                    'mp4a'  => 'audio/mp4',
                    'aac'   => 'audio/x-aac',
                    'aif'   => 'audio/x-aiff',
                    'aiff'  => 'audio/x-aiff',
                    'wav'   => 'audio/x-wav',
                    'wma'   => 'audio/x-ms-wma',
                    'mpeg'  => 'video/mpeg',
                    'mpg'   => 'video/mpeg',
                    'mp4'   => 'video/mp4',
                    'mov'   => 'video/quicktime',
                    'avi'   => 'video/x-msvideo',
                    'wmv'   => 'video/x-ms-wmv',
                );

                $extension = substr(strrchr($file, '.'), 1);

                if ($mimetypes[strtolower($extension)] !== null) {
                    $mime_type = $mimetypes[$extension];
                } else {
                    $mime_type = 'application/octet-stream';
                }
            }

            return $mime_type;
        }
        return false;
    }
public function getMimeType($file)
    {
        if (!empty($file)) {
            // in PHP 5.3 we can use 'finfo'
            if (PHP_VERSION_ID >= 50300 && function_exists('finfo_open')) {
                $finfo = finfo_open(FILEINFO_MIME_TYPE);
                $mime_type = finfo_file($finfo, $file);
                finfo_close($finfo);
            } else {
                // A few mimetypes to "guess" using the file extension.
                $mimetypes = array(
                    'txt'   => 'text/plain',
                    'csv'   => 'text/csv',
                    'pdf'   => 'application/pdf',
                    'doc'   => 'application/msword',
                    'docx'  => 'application/msword',
                    'xls'   => 'application/vnd.ms-excel',
                    'ppt'   => 'application/vnd.ms-powerpoint',
                    'eps'   => 'application/postscript',
                    'zip'   => 'application/zip',
                    'gif'   => 'image/gif',
                    'jpg'   => 'image/jpeg',
                    'jpeg'  => 'image/jpeg',
                    'png'   => 'image/png',
                    'mp3'   => 'audio/mpeg',
                    'mp4a'  => 'audio/mp4',
                    'aac'   => 'audio/x-aac',
                    'aif'   => 'audio/x-aiff',
                    'aiff'  => 'audio/x-aiff',
                    'wav'   => 'audio/x-wav',
                    'wma'   => 'audio/x-ms-wma',
                    'mpeg'  => 'video/mpeg',
                    'mpg'   => 'video/mpeg',
                    'mp4'   => 'video/mp4',
                    'mov'   => 'video/quicktime',
                    'avi'   => 'video/x-msvideo',
                    'wmv'   => 'video/x-ms-wmv',
                );

                $extension = substr(strrchr($file, '.'), 1);

                if ($mimetypes[strtolower($extension)] !== null) {
                    $mime_type = $mimetypes[$extension];
                } else {
                    $mime_type = 'application/octet-stream';
                }
            }

            return $mime_type;
        }
        return false;
    }
public function getMimeType ( $ file ) { if ( ! empty ( $ file ) ) { // in PHP 5.3 we can use 'finfo' if ( PHP_VERSION_ID >= 50300 && function_exists ( 'finfo_open' ) ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime_type = finfo_file ( $ finfo , $ file ) ; finfo_close ( $ finfo ) ; } else { // A few mimetypes to "guess" using the file extension. $ mimetypes = array ( 'txt' => 'text/plain' , 'csv' => 'text/csv' , 'pdf' => 'application/pdf' , 'doc' => 'application/msword' , 'docx' => 'application/msword' , 'xls' => 'application/vnd.ms-excel' , 'ppt' => 'application/vnd.ms-powerpoint' , 'eps' => 'application/postscript' , 'zip' => 'application/zip' , 'gif' => 'image/gif' , 'jpg' => 'image/jpeg' , 'jpeg' => 'image/jpeg' , 'png' => 'image/png' , 'mp3' => 'audio/mpeg' , 'mp4a' => 'audio/mp4' , 'aac' => 'audio/x-aac' , 'aif' => 'audio/x-aiff' , 'aiff' => 'audio/x-aiff' , 'wav' => 'audio/x-wav' , 'wma' => 'audio/x-ms-wma' , 'mpeg' => 'video/mpeg' , 'mpg' => 'video/mpeg' , 'mp4' => 'video/mp4' , 'mov' => 'video/quicktime' , 'avi' => 'video/x-msvideo' , 'wmv' => 'video/x-ms-wmv' , ) ; $ extension = substr ( strrchr ( $ file , '.' ) , 1 ) ; if ( $ mimetypes [ strtolower ( $ extension ) ] !== null ) { $ mime_type = $ mimetypes [ $ extension ] ; } else { $ mime_type = 'application/octet-stream' ; } } return $ mime_type ; } return false ; }
Gets mime type of a file.

For email attachments, the mime type is very important.
Uses the PHP 5.3 function `finfo_open` when available, otherwise falls
back to using a mapping of known of common mimetypes. If no matches
are found `application/octet-stream` will be returned.

@author Michael Eichelsdoerfer
@author Huib Keemink
@param string $file
@return string|boolean
the mime type of the file, or false is none found
Gets mime type of a file .