Uses
Uses | Description |
---|---|
wp-includes/functions.php: get_allowed_mime_types() | Retrieve list of allowed mime types and file extensions. |
Retrieve the file type from the file name.
You can optionally define the mime array, if needed.
(string) (Required) File name or path.
(string[]) (Optional) Array of mime types keyed by their file extension regex.
Default value: null
(array) Values for the extension and mime type.
File: wp-includes/functions.php
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' ); }
Version | Description |
---|---|
2.0.4 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_check_filetype