Title: wp_match_mime_types
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_match_mime_types( string|string[] $wildcard_mime_types, string|string[] $real_mime_types ): array

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#changelog)

Checks a MIME-Type against a list.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#description)󠁿

If the `$wildcard_mime_types` parameter is a string, it must be comma separated 
list. If the `$real_mime_types` is a string, it is also comma separated to create
the list.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#parameters)󠁿

 `$wildcard_mime_types`string|string[]required

Mime types, e.g. `audio/mpeg`, `image` (same as `image/*`), or `flash` (same as `*
flash*`).

`$real_mime_types`string|string[]required

Real post mime type values.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#return)󠁿

 array array(wildcard=>array(real types)).

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#source)󠁿

    ```php
    function wp_match_mime_types( $wildcard_mime_types, $real_mime_types ) {
    	$matches = array();
    	if ( is_string( $wildcard_mime_types ) ) {
    		$wildcard_mime_types = array_map( 'trim', explode( ',', $wildcard_mime_types ) );
    	}
    	if ( is_string( $real_mime_types ) ) {
    		$real_mime_types = array_map( 'trim', explode( ',', $real_mime_types ) );
    	}

    	$patternses = array();
    	$wild       = '[-._a-z0-9]*';

    	foreach ( (array) $wildcard_mime_types as $type ) {
    		$mimes = array_map( 'trim', explode( ',', $type ) );
    		foreach ( $mimes as $mime ) {
    			$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );

    			$patternses[][ $type ] = "^$regex$";

    			if ( ! str_contains( $mime, '/' ) ) {
    				$patternses[][ $type ] = "^$regex/";
    				$patternses[][ $type ] = $regex;
    			}
    		}
    	}
    	asort( $patternses );

    	foreach ( $patternses as $patterns ) {
    		foreach ( $patterns as $type => $pattern ) {
    			foreach ( (array) $real_mime_types as $real ) {
    				if ( preg_match( "#$pattern#", $real )
    					&& ( empty( $matches[ $type ] ) || ! in_array( $real, $matches[ $type ], true ) )
    				) {
    					$matches[ $type ][] = $real;
    				}
    			}
    		}
    	}

    	return $matches;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/post.php#L3712)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/post.php#L3712-L3752)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#related)󠁿

| Used by | Description | 
| [media_upload_library_form()](https://developer.wordpress.org/reference/functions/media_upload_library_form/)`wp-admin/includes/media.php` |

Outputs the legacy media upload form for the media library.

  | 
| [get_media_item()](https://developer.wordpress.org/reference/functions/get_media_item/)`wp-admin/includes/media.php` |

Retrieves HTML form for modifying the image attachment.

  | 
| [wp_ajax_upload_attachment()](https://developer.wordpress.org/reference/functions/wp_ajax_upload_attachment/)`wp-admin/includes/ajax-actions.php` |

Handles uploading attachments via AJAX.

  | 
| [WP_Media_List_Table::get_views()](https://developer.wordpress.org/reference/classes/wp_media_list_table/get_views/)`wp-admin/includes/class-wp-media-list-table.php` |

Gets an array of links for the available views on this table.

  | 
| [Custom_Image_Header::step_2_manage_upload()](https://developer.wordpress.org/reference/classes/custom_image_header/step_2_manage_upload/)`wp-admin/includes/class-custom-image-header.php` |

Uploads the file to be cropped in the second step.

  | 
| [Custom_Background::handle_upload()](https://developer.wordpress.org/reference/classes/custom_background/handle_upload/)`wp-admin/includes/class-custom-background.php` |

Handles an Image upload for the background image.

  | 
| [wp_mime_type_icon()](https://developer.wordpress.org/reference/functions/wp_mime_type_icon/)`wp-includes/post.php` |

Retrieves the icon for a MIME type or attachment.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_match_mime_types/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_match_mime_types%2F)
before being able to contribute a note or feedback.