wp_check_filetype
函数
wp_check_filetype ( $filename, $mimes = null )
- 参数
-
-
(string)
$filename
File name or path.- Required: 是
-
(string[])
$mimes
Optional. Array of allowed mime types keyed by their file extension regex.- Required: 否
- Default: null
-
(string)
- 返回值
-
- (array) { Values for the extension and mime type. @type string|false $ext File extension, or false if the file doesn’t match a mime type. @type string|false $type File mime type, or false if the file doesn’t match a mime type. }
- 定义位置
-
-
wp-includes/functions.php
, line 3018
-
wp-includes/functions.php
- 引入
- 2.0.4
- 弃用
- –
Retrieves 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' ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。