File send sample code using PHP curl

 

<?php



$cfile = curl_file_create('path/to/file.ext');

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://example.com/upload",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('file' => $cfile),
  CURLOPT_HTTPHEADER => array(
    "Content-Type: multipart/form-data"
  ),
));

$response = curl_exec($curl);

curl_close($curl);

echo $response;

?>