Title: wp_handle_upload_prefilter
Published: April 25, 2014

---

# apply_filters( ‘wp_handle_upload_prefilter’, array $file )

## In this article

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

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

Filter data for the current file to upload.

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

 `$file`array

An array of data for a single file.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/?output_format=md#more-information)󠁿

When you upload Media from your WordPress admin dashboard, `wp_handle_upload` is
called once for each file the user specified. `wp_handle_upload_prefilter` is an
admin filter that is called by the `wp_handle_upload` function. The single parameter,`
$file`, represent a single element of the `$_FILES` array. The `wp_handle_upload_prefilter`
provides you with an opportunity to examine or alter the filename before the file
is moved to its final location.

Using this, in conjunction with the `upload_dir`, you can dynamically determine 
which directory to upload to, based on the files you upload.

    ```php
    add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );

    function custom_upload_filter( $file ) {
    $file['name'] = 'wordpress-is-awesome-' . $file['name'];
    return $file;
    }
    ```

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

    ```php
    'text',
    ```

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

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

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

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

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/?output_format=md#comment-content-5717)
 2.    [David Aguilera](https://profiles.wordpress.org/davilera/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/#comment-5717)
 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_handle_upload_prefilter%2F%23comment-5717)
     Vote results for this note: 4[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_handle_upload_prefilter%2F%23comment-5717)
 4.  **Example:** Prevent images larger than 200kb from being uploaded.
 5.      ```php
         function plugin_prefix_max_image_size( $file ) {
           $limit    = 200;
           $size     = $file['size'] / 1024;
           $is_image = strpos( $file['type'], 'image' ) !== false;
           if ( $is_image && $size > $limit ) {
             $file['error'] = "Image files must be smaller than {$limit}kb";
           }
           return $file;
         }
         add_filter( 'wp_handle_upload_prefilter', 'plugin_prefix_max_image_size' );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_handle_upload_prefilter%2F%3Freplytocom%3D5717%23feedback-editor-5717)
 7.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/?output_format=md#comment-content-2359)
 8.    [Milana Cap](https://profiles.wordpress.org/milana_cap/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/#comment-2359)
 9.  [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_handle_upload_prefilter%2F%23comment-2359)
     Vote results for this note: 1[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_handle_upload_prefilter%2F%23comment-2359)
 10. It is not deprecated, it is converted to a dynamic hook with `$action` since 4.0.–
     [track](https://core.trac.wordpress.org/browser/tags/4.8/src/wp-admin/includes/file.php#L260)
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_handle_upload_prefilter%2F%3Freplytocom%3D2359%23feedback-editor-2359)
 12.  [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/?output_format=md#comment-content-3916)
 13.   [Jules Colle](https://profiles.wordpress.org/jules-colle/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/#comment-3916)
 14. [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_handle_upload_prefilter%2F%23comment-3916)
     Vote results for this note: -1[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_handle_upload_prefilter%2F%23comment-3916)
 15. Example: prepend all uploaded files with `wordpress-is-awesome-`
 16.     ```php
         add_filter( 'wp_handle_upload_prefilter', function( $file ) {
             $file['name'] = 'wordpress-is-awesome-' . $file['name'];
             return $file;
         } );
         ```
     
 17. (According to [https://wordpress.stackexchange.com/a/333935/5986](https://wordpress.stackexchange.com/a/333935/5986)
     this code was originally in the docs. I’m adding it here again since I can’t find
     it anywhere else.)
 18.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_handle_upload_prefilter%2F%3Freplytocom%3D3916%23feedback-editor-3916)
 19.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/?output_format=md#comment-content-2326)
 20.   [slickremix](https://profiles.wordpress.org/slickremix/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/wp_handle_upload_prefilter/#comment-2326)
 21. [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_handle_upload_prefilter%2F%23comment-2326)
     Vote results for this note: -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_handle_upload_prefilter%2F%23comment-2326)
 22. This Filter appears to be Depreciated as of WordPress version 4.4
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_handle_upload_prefilter%2F%3Freplytocom%3D2326%23feedback-editor-2326)

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