I am trying to send an image file to an API through curl in php, but when I try to give my request the file I need, it proceeds to fail when I call curl_exec on it.
The path I'm providing to the file is valid, I used var_dump on my CURLFile object when I created it and it seems fine. When curl_exec is called the request instantly fails and returns false. But, if I replace the CURLFile object by a string in CURLOPT_POSTFIELDS the request works perfectly.
$ch = curl_init('http://localhost/test/test.php');
$curlfile = new CURLFile($path,'image/png','image');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,array('image' => $curlfile));
curl_exec($curl);//Returns false
$ch = curl_init('http://localhost/test/test.php');
$curlfile = new CURLFile($path,'image/png','image');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,array('image' => "somestring"));
curl_exec($curl);//Returns true