wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_check_filetype › WordPress Function

Seit2.0.4
Veraltetn/v
wp_check_filetype ( $filename, $mimes = null )
Parameter: (2)
  • (string) $filename File name or path.
    Erforderlich: Ja
  • (string[]|null) $mimes Optional. Array of allowed mime types keyed by their file extension regex. Defaults to the result of get_allowed_mime_types().
    Erforderlich: Nein
    Standard: null
Gibt zurück:
  • (array) { Values for the extension and mime type. @type string|false $ext File extension, or false if the file doesn't match a mime type. @type string|false $type File mime type, or false if the file doesn't match a mime type. }
Definiert in:
Codex:

Retrieves the file type from the file name.

You can optionally define the mime array, if needed.


Quellcode

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