function wp_check_filetype( $filename, $mimes = null ) {}

Retrieve the file type from the file name.
You can optionally define the mime array, if needed.


  • string $filename: File name or path.
  • array $mimes: Optional. Key is the file extension with value as the mime type.

Return values

returns:Values with extension first and mime type.

Source code

function wp_check_filetype( $filename, $mimes = null ) {

	if ( empty($mimes) )

		$mimes = get_allowed_mime_types();

	$type = false;

	$ext = false;

	foreach ( $mimes as $ext_preg => $mime_match ) {

		$ext_preg = '!\.(' . $ext_preg . ')$!i';

		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {

			$type = $mime_match;

			$ext = $ext_matches[1];




	return compact( 'ext', 'type' );



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: