cURL upload in PHP / "no file found"

deals
forms

#1

Hi,
I tried to upload .pdf files from my personal CRM to Hubspot root folder with PHP :

$url = "http://api.hubapi.com/filemanager/api/v2/files?hapikey=".$hapikey;//change your api key here
$realpath = "http://localhost:8888/steps/D_201803_14122.pdf";
$headers = array("Content-Type:multipart/form-data"); // cURL headers for file uploading
$postfields = array("files"=>$realpath,'file_names'=>'D_201803_14122FROMPHP.pdf');
$ch = curl_init();
$options = array(
  CURLOPT_URL => $url,
  CURLOPT_HEADER => true,
  CURLOPT_POST => 1,
  CURLOPT_HTTPHEADER => $headers,
  CURLOPT_POSTFIELDS => $postfields,
  CURLOPT_RETURNTRANSFER => true
); // cURL options
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result;
if(!curl_errno($ch)) {
  $info = curl_getinfo($ch);
  if ($info['http_code'] == 200)
  $msg = "File uploaded successfully";
  echo $msg;
} else {
  $errmsg = curl_error($ch);
  echo $errmsg;
}

curl_close($ch); 

And I get this error :
{"status":"error","message":"no file found, please set name to 'files' or 'files[]'","correlationId":"d6ae2bcc-c26d-48db-91a9-d601cea56e7e","requestId":"5364051dc0127abf389ecf56f185f994"}

The pdf file is in the same folder as the php script.
What's wrong with this piece of code ?

Thanks.

UPDATE : I tried with different paths like :
$realpath = "D_201803_14122.pdf";
$realpath = '@'."D_201803_14122.pdf";
Still the same error


#2

Hey @MathieuDuboy, can you upload a file that doesn't exist on your localhost? So just the file path from your computer instead of the path being on localhost? That's the only thing I can think of that would be causing the issue.