wp_check_filetype( string $filename, string[] $mimes = null ): array
Retrieves the file type from the file name.
Description
You can optionally define the mime array, if needed.
Parameters
-
$filename
string Required -
File name or path.
-
$mimes
string[] Optional -
Array of allowed mime types keyed by their file extension regex.
Defaults to the result of get_allowed_mime_types() .Default:
null
Return
array Values for the extension and mime type.
ext
string|falseFile extension, or false if the file doesn't match a mime type.type
string|falseFile mime type, or false if the file doesn't match a mime type.
Source
File: wp-includes/functions.php
.
View all references
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' );
}
Changelog
Version | Description |
---|---|
2.0.4 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example