返回介绍

check_upload_mimes()

发布于 2017-09-10 21:40:58 字数 2182 浏览 1187 评论 0 收藏 0

check_upload_mimes( array $mimes )

Check an array of MIME types against a whitelist.


description

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.


参数

$mimes

(array) (Required)


返回值

(array)


源代码

File: wp-includes/ms-functions.php

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

更新日志

Versiondescription
MUIntroduced.

相关函数

Uses

  • wp-includes/option.php: get_site_option()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Get allowed MIME types

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

    Output:

    
    Array( 'jpg|jpeg|jpe' => 'image/jpeg' )
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文