WordPress函数文档check_upload_mimes()
判断是否为允许上传的附件类型 描述 Check an array of MIME types against …
判断是否为允许上传的附件类型
描述
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.
用法
<?php check_upload_mimes( $mimes ) ?>
参数
$mimes
(array) (必填) MIME types to check.
默认值: None
示例
1
2
3
4
5
6
7
8
9
10
11
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
<?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’ );
?>
|
历史
添加于 版本: MU (WordPress 3.0.0)
源文件
check_upload_mimes() 函数的代码位于 wp-includes/ms-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* 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;
}
|
相关
wp_get_mime_types(),
get_allowed_mime_types(),
wp_check_filetype_and_ext()
- 原文:http://codex.wordpress.org/Function_Reference/check_upload_mimes
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!