Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_check_filetype ›

Depuis2.0.4
Dépréciéen/a
wp_check_filetype ( $filename, $mimes = null )
Paramètres: (2)
  • (string) $filename File name or path.
    Requis: Oui
  • (array) $mimes Optional. Key is the file extension with value as the mime type.
    Requis: Non
    Défaut: null
Retourne:
  • (array) Values with extension first and mime type.
Défini(e) dans:
Codex:

Retrieve the file type from the file name.

You can optionally define the mime array, if needed.



Source

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' );
}