
如何使用代码和插件创建WordPress活动事件
wp_check_filetype ( $filename, $mimes = null )
wp_check_filetype: 这是一个检查某文件类型是否允许上传到网站的函数。它可以用来确保只有某些文件类型被允许上传到网站。
从文件名中获取文件类型。
如果需要,你可以选择性地定义mime数组。
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' ); }