check_upload_mimes()判断是否为允许上传的附件类型

目录

描述

Check an array of MIME types against a whitelist. All types not on the whitelist are filtered out, and only the allowed types are returned.

WordPress ships with a set of allowed upload file types, which is defined in wp-includes/functions.php in get_allowed_mime_types(). This function is used to filter that list against the filetype whitelist provided by Multisite Super Admins at wp-admin/network/settings.php.

check_upload_mimes() 描述

用法

<?php check_upload_mimes$mimes ?>

check_upload_mimes() 用法

参数

$mimes

(array) (必填) MIME types to check.

默认值: None

check_upload_mimes() 参数

示例

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php

$mimes = array(
        'jpg|jpeg|jpe' => 'image/jpeg',
        'php'          => 'application/x-php', // This isn't on the whitelist!
);

$mimes = check_upload_mimes( $mimes );

// array( 'jpg|jpeg|jpe' => 'image/jpeg' );

?>

check_upload_mimes() 示例

历史

添加于 版本: MU (WordPress 3.0.0)

check_upload_mimes() 历史

源文件

check_upload_mimes() 函数的代码位于 wp-includes/ms-functions.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Check an array of MIME types against a whitelist.
 *
 * WordPress ships with a set of allowed upload filetypes,
 * which is defined in wp-includes/functions.php in
 * get_allowed_mime_types(). This function is used to filter
 * that list against the filetype whitelist provided by Multisite
 * Super Admins at wp-admin/network/settings.php.
 *
 * @since MU
 *
 * @param array $mimes
 * @return array
 */
function check_upload_mimes( $mimes ) {
	$site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
	$site_mimes = array();
	foreach ( $site_exts as $ext ) {
		foreach ( $mimes as $ext_pattern => $mime ) {
			if ( $ext != '' && strpos( $ext_pattern, $ext ) !== false )
				$site_mimes[$ext_pattern] = $mime;
		}
	}
	return $site_mimes;
}

check_upload_mimes() 源文件

相关