Core Function
View Source on Trac ↗ media_handle_upload()
media_handle_upload(
mixed $file_id,
mixed $post_id,
mixed $post_data = array(),
mixed $overrides = array('test_form' => false)
) Saves a file submitted from a POST request and create an attachment post for it.
Parameters 2 required
| Name / Type | Description |
|---|---|
| $file_id string | Index of the `$_FILES` array that the file was sent. Required |
| int | $post_id The post ID of a post to attach the media item to. Required, but can be set to 0, creating a media item that has no relationship to a post. Required |
| $post_data array | Optional. Overwrite some of the attachment. |
| $overrides array | Optional. Override the wp_handle_upload() behavior. |
Return Value
((int)
| WP_Error) ID of the attachment or a WP_Error object on failure.
Function Information
Since Version
2.5.0
Source File
wp-admin/includes/media.php
Advertisement