<?php

    $sessiontoken = "k7uhook39qa4abb0naot8p25r4";
    $url = "localhost/glpi";
    $apptoken = "jYPzF6c9j9pTDBdZXwIBsGxzoGhoWyef4wXUAsr2";
    $filename = "/tmp/image4.png";

$file = file_get_contents($filename);
 
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://".$url."/apirest.php/Document/",
  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
Content-Disposition: form-data; name=\"uploadManifest\"
 
{\"input\": {\"tickets_id\": \"4\",\"name\": \"01Chamado 1234567bc\", \"_filename\" : [\”$filename\”]}}
——WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: multipart/form-data; name=\"ab\"; filename=\"$filename\";
Content-Type: image/png;
 
$file
——WebKitFormBoundary7MA4YWxkTrZu0gW–",
  CURLOPT_HTTPHEADER => array(
    "app-token: $apptoken",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=—-WebKitFormBoundary7MA4YWxkTrZu0gW",
    "postman-token: 3cc7a7f0-2f01-36dc-8ccc-a8b263d2e26c",
    "session-token: $sessiontoken"
  ),
));

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

curl_close($curl);

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

?>