0

I have been creating a script to insert data from a JSON file to a POST request.

While it does what it needs to download the image in the URL supplied than it needs to download it and perform a post request on my route.

I have been struggling for the past few hours to get it working but no success.

I have used realpath and CurlFile but it didn't make it work.

Here is the request:

<?php
$image = $this->makeCurlFile(realpath("scorpion_stretch-59788999e4432d80.jpg"));

$body = ["name" => "uploaded_file", "filename" => $image->name];

echo print_r($body);

$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => "https://resources.diamondappgroup.com/upload.php",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_HTTPHEADER => array(
        "Accept: */*",
        "Cache-Control: no-cache",
        "Connection: keep-alive",
        "Content-Type: application/x-www-form-urlencoded",
        "Host: resources.diamondappgroup.com",
        "Postman-Token: 45ebd192-9621-482c-8735-2061bc31c6fa,6a7a959f-372d-4afb-9efa-6b4da47ea1b0",
        "User-Agent: PostmanRuntime/7.11.0",
        "accept-encoding: gzip, deflate",
        "cache-control: no-cache",
        "content-length: 312659",
        "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.