Function Reference/wp handle upload
Description
Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type, and moving the file to the appropriate directory within the uploads directory.
Usage
<?php wp_handle_upload( $file, $overrides, $time ); ?>
Parameters
- $file
- (array) (required) Reference to a single element of $_FILES. Call the function once for each uploaded file. Passed by reference, so you must pass a variable.
- Default: None
- $overrides
- (array) (optional) An associative array to override default variables with extract( $overrides, EXTR_OVERWRITE ). If you don’t pass 'test_form' => FALSE the upload will be rejected.
- Default: false
- $time
- (string) (optional) Time formatted in 'yyyy/mm'. Passed to wp_upload_dir().
- Default: NULL
Return values
On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
The return values on success:
- file
- (string) The local path to the uploaded file.
- url
- (string) The public URL for the uploaded file.
- type
- (string) The MIME type.
type and file may be used with wp insert attachment().
Further Reading
Source File
wp_handle_upload() is located in /wp-admin/includes/file.php.