wp_check_filetype() – Retrieve the file type from the file name.

You appear to be a bot. Output may be restricted

Description

Retrieves the file type from the file name.

You can optionally define the mime array, if needed.

Usage

$array = wp_check_filetype( $filename, $mimes );

Parameters

$filename
( string ) required – File name or path.
$mimes
( string[]|null ) optional – Optional. Array of allowed mime types keyed by their file extension regex. Defaults to the result of get_allowed_mime_types().
$ext
( string|false ) optional – File extension, or false if the file doesn't match a mime type.
$type
( string|false ) optional – File mime type, or false if the file doesn't match a mime type. }

Returns

array { Values for the extension and mime type.

Source

File name: wordpress/wp-includes/functions.php
Lines:

1 to 18 of 18
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' );
}
 

 View on GitHub View on Trac