wp_check_filetype()
wp_check_filetype( string $filename, string[] $mimes = …
wp_check_filetype( string $filename, string[] $mimes = null )
从文件名中检索文件类型。
Retrieve the file type from the file name.
从文件名中检索文件类型。
Retrieve the file type from the file name.
目录锚点:#说明#参数#源码#笔记
说明(Description)
如果需要,可以选择定义mime数组。
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $filename | (string) | 文件名或路径。 |
| $mimes | (string[]) | 由文件扩展名regex键控的mime类型数组。 |
源码(Source)
/**
* Retrieve the file type from the file name.
*
* You can optionally define the mime array, if needed.
*
* @since 2.0.4
*
* @param string $filename File name or path.
* @param array $mimes Optional. Key is the file extension with value as the mime type.
* @return array Values with extension first and mime type.
*/
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' );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.0.4 | wp-includes/functions.php | 20 | 3 |
笔记(Notes)
基本示例
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!