wp_check_filetype() WP 1.0
Retrieve the file type from the file name.
You can optionally define the mime array, if needed.
1 time = 0.0011148s = very slow | 50000 times = 1.85s = fast | PHP 7.3.12, WP 5.4.1
No Hooks.
Return
Array. Values for the extension and mime type.
-
ext(string/false)
File extension, or false if the file doesn't match a mime type. - type(string/false)
File mime type, or false if the file doesn't match a mime type.
Usage
wp_check_filetype( $filename, $mimes );
- $filename(string) (required)
- File name or path.
- $mimes(string[])
- Array of mime types keyed by their file extension regex.
Default: null
Changelog
Since 2.0.4 | Introduced. |
Code of wp_check_filetype() wp check filetype WP 5.6
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' );
}