WordPress at a glance

wp_check_filetype() WP 1.0

Retrieve the file type from the file name.

You can optionally define the mime array, if needed.

No Hooks.

Return

Array. Values with extension first and mime type.

Usage

wp_check_filetype( $filename, $mimes );
$filename(string) (required)
File name or path.
$mimes(array)
Key is the file extension with value as the mime type.
Default: null

Code of wp_check_filetype: wp-includes/functions.php VER 4.9.8

<?php
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];
			break;
		}
	}

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

Related Functions

From category: Rarely used

No comments
    Hello, !     Log In . Register