protected function _detectFileMimeType($file)
    {
        $type = null;
        
        // First try with fileinfo functions
        if (function_exists('finfo_open')) {
            if (self::$_fileInfoDb === null) {
                self::$_fileInfoDb = @finfo_open(FILEINFO_MIME);
            }
            
            if (self::$_fileInfoDb) { 
                $type = finfo_file(self::$_fileInfoDb, $file);
            }
            
        } elseif (function_exists('mime_content_type')) {
            $type = mime_content_type($file);
        }
        
        // Fallback to the default application/octet-stream
        if (! $type) {
            $type = 'application/octet-stream';
        }
        
        return $type;
    }