WordPress Image Upload Errror

WordPress Image Upload Errror

$attachment = media_sideload_image( $mediaURL , $postId );

if ( is_wp_error( $attachment ) )
{
    file_put_contents(dirname(__FILE__)."/../backend/form/add-entry.log", print_r($attachment, true)."\r\n", FILE_APPEND);
}

$media = get_attached_media( 'image', $postId );

if( count( $media ) > 0 ) 
{
    $keys = array_keys( $media );
    set_post_thumbnail( $postId, $media[ $keys[0] ]->ID ); // setting this as the featured image for editing
}
Comments are closed.