WordPress开发者和主题制作者的搜索引擎



wp_check_filetype ›

Since2.0.4
已弃用n/a
wp_check_filetype ( $filename, $mimes = null )
参数: (2)
  • (string) $filename File name or path.
    Required: Yes
  • (array) $mimes Optional. Key is the file extension with value as the mime type.
    Required: No
    默认: null
返回:
  • (array) Values with extension first and mime type.
定义在:
文档:

Retrieve the file type from the file name.

You can optionally define the mime array, if needed.



源码

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' );
}