// Do the validation and storage stuff.
$id =
media_handle_sideload( $file_array,
$post_id,
$desc );
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) { @
unlink( $file_array['tmp_name'
] );
return $id;
} // Store the original attachment source in meta.
add_post_meta( $id, '_source_url',
$file );
// If attachment ID was requested, return it.
if ( 'id' ===
$return_type ) { return $id;
} $src =
wp_get_attachment_url( $id );
} // Finally, check to make sure the file has been saved, then return the HTML.
if ( !
empty( $src ) ) {