-3

I want to upload videos to put.re, a file hosting provider using php curl

I tried this code:

    foreach ($_FILES['uploadvid']['tmp_name'] as $index => $fileTmpName) {
    $fileName =  $_FILES['uploadvid']['name'];
    $size = $_FILES['uploadvid']['size'];
        $handle = fopen($fileTmpName, "r");
        $data = fread($handle, filesize($fileTmpName));
        $curl = curl_init();
                curl_setopt_array($curl, array(
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_URL => "https://api.put.re/upload",
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => array( 'file' => @ $data),
        ));
        $response = curl_exec($curl);
        $err = curl_error($curl);
        curl_close($curl);
        $pms = json_decode($response, true);
        $vidurl = $pms['data']['link'];
    if ($vidurl!="") {
        echo 'Success';
    } else {
        echo 'Problem';
        echo $err;
echo $response;
    }
}

But this echo Problem. If you check the api docs, you will see there is no output for error. You can check The Api Docs here . There is no example shown in it's site.

The $err returns nothing,
the $reponse returns a message: NO files(s) found.


I think there is a mistake in the API call...
Please Help me to get through this.

Please NOTE that, I want to upload videos, not images. put.re allows any kind of file to be uploaded. I tried to upload files less than 100mb (which is a limit)

1 Answers1

0

Can you share more detail about the error you getting ? For example i tried the api with code at below and get response which says upload disabled.

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.put.re/upload",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example.png\"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  CURLOPT_HTTPHEADER => array(
    "Accept: */*",
    "Accept-Encoding: gzip, deflate",
    "Cache-Control: no-cache",
    "Connection: keep-alive",
    "Content-Length: 20895",
    "Content-Type: application/x-www-form-urlencoded",
    "Host: api.put.re",
    "User-Agent: PostmanRuntime/7.20.1",
    "cache-control: no-cache",
    "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;
}