Laravel post image from url

how to send an image to another api, via file_get_contents

$date = new DateTime(); $uuid_v4 = 'UUID'; //generate universally unique identifier version 4 (RFC 4122)

    $itemData = json_encode(
        array(
            'name' => "NAME",
            'externalId' => $name_externalId,
            'photos' => file_get_contents("https://i.pinimg.com/originals/b1/3b/81/b13b81d79fe91e35008feeaf4c5b04d7.jpg"),
            'data' => array(
                'type' => 'ITEM',
                'price' => 1000,
                'description' => "description",
                'measurement' => "GRAM",
            )
        )
    );

    $opts = array(
        'http' => array(
            'method' => 'POST',
            'header' => "Accept: application/json\r\n" .
                "Accept-Charset: utf-8\r\n" .
                "Content-Type: application/json\r\n" .
                "Authorization: Basic ". base64_encode("$companyId:$apiKey")."\r\n" .
                "Content-Type: application/json\r\n" .
                "X-Origin-Request-Id: ".$uuid_v4."\r\n" .
                "X-Timestamp: ".$date->format(DateTime::ATOM),
            'content' => $itemData,
            'ignore_errors' => true
        )
    );

    $context = stream_context_create($opts);
    $result = file_get_contents($url, false, $context);

    return $result;

Ответы (0 шт):