Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp check filetype and ext


Attempts to determine the real file type of a file.
If unable to, the file name extension will be used to determine type. If it's determined that the extension does not match the file's real type, then the "proper_filename" value will be set with a proper filename and extension.


wp_check_filetype_and_ext$file$filename$mimes );

$validate['proper_filename'] !== false )
$filename $validate['proper_filename'];


(string) (required) Full path to the image.
Default: None
(string) (required) The filename of the image (may differ from $file due to $file being in a tmp directory)
Default: None
(array) (null) optional
Default: None

Return Values

Values for the extension, MIME, and either a corrected filename or false if original $filename is valid
  • ['ext'] - Extension (eg 'jpg')
  • ['type'] - Mime Type (eg 'image/jpeg')
  • ['proper_filename'] - (boolean) false or a string containing a proper file name if the original was invalid.



Currently this function only supports validating images known to getimagesize().

If using in a plugin/theme and you get an error about this function not being defined, you probably need to add require_once ABSPATH .'wp-admin/includes/file.php'; before the function gets called.

Change Log

Since: 3.0.0



Source File

wp_check_filetype_and_ext() is located in wp-includes/functions.php

See also index of Function Reference and index of Template Tags.
This article is marked as in need of editing. You can help Codex by editing it.