Function: media_handle_sideload

media_handle_sideload( array $file_array, integer $post_id, string $desc, array $post_data )

Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().

Parameters

Name Type(s) Default Value Description
$file_array array

Array similar to a $_FILES upload array.

$post_id integer

The post ID the media is associated with.

$desc string null

Optional. Description of the side-loaded file. Default null.

$post_data array array()

Optional. Post data to override. Default empty array.

Returns

integer | object

The ID of the attachment or a WP_Error on failure.

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.