wp_check_filetype( string $filename, array $mimes = null )
Retrieve the file type from the file name.
Description Description
You can optionally define the mime array, if needed.
Parameters Parameters
- $filename
-
(string) (Required) File name or path.
- $mimes
-
(array) (Optional) Key is the file extension with value as the mime type.
Default value: null
Return Return
(array) Values with extension first and mime type.
Source Source
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' );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 2.0.4 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
<?php $filetype = wp_check_filetype('image.jpg'); echo $filetype['ext']; // will output jpg ?>