Title: wp_check_filetype_and_ext
Published: April 25, 2014
Last modified: August 20, 2026

---

# apply_filters( ‘wp_check_filetype_and_ext’, array $wp_check_filetype_and_ext, string $file, string $filename, string[]|null $mimes, string|false $real_mime )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#wp--skip-link--target)

Filters the “real” file type of the given file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#parameters)󠁿

 `$wp_check_filetype_and_ext`array

Values for the extension, mime type, and corrected filename.

 * `ext` string|false
 * File extension, or false if the file doesn’t match a mime type.
 * `type` string|false
 * File mime type, or false if the file doesn’t match a mime type.
 * `proper_filename` string|false
 * File name with its correct extension, or false if it cannot be determined.

`$file`string

Full path to the file.

`$filename`string

The name of the file (may differ from $file due to $file being in a tmp directory).

`$mimes`string[]|null

Array of mime types keyed by their file extension regex, or null if none were provided.

`$real_mime`string|false

The actual mime type or false if the type cannot be determined.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#source)󠁿

    ```php
    return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/functions.php#L3352)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/functions.php#L3352-L3352)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_check_filetype_and_ext()](https://developer.wordpress.org/reference/functions/wp_check_filetype_and_ext/)`wp-includes/functions.php` |

Attempts to determine the real file type of a file.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | The `$real_mime` parameter was added. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/?output_format=md#comment-content-7173)
 2.   [fabioz](https://profiles.wordpress.org/webdisrupt/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/#comment-7173)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_check_filetype_and_ext%2F%23comment-7173)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_check_filetype_and_ext%2F%23comment-7173)
 4. You will want to use this filter as the function `finfo_file` from PHP doesn’t 
    always detect CSV files as `text/plain` or `text/csv`, instead it is tagged as `
    application/octet-stream`.
 5. This creates a problem since WordPress will not allow you to upload the file to
    the library or even WooCommerce import and therefore you can use the filter as 
    follows.
 6. The following code will help avoid using `ALLOW_UNFILTERED_UPLOADS` when all you
    need to enable is one file type.
 7.     ```php
        add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename ) {
          // Get the extension of the uploaded file
          $ext = pathinfo( $filename, PATHINFO_EXTENSION );
    
          // Check if the file extension is CSV
          if ( 'csv' === $ext ) {
              $data[‘ext’]  = 'csv';
              $data[‘type’] = 'text/csv';
          }
    
          return $data;
        }, 10, 3 );
        ```
    
 8.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_check_filetype_and_ext%2F%3Freplytocom%3D7173%23feedback-editor-7173)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_check_filetype_and_ext%2F)
before being able to contribute a note or feedback.