I have a string that representing a file path like this: D:/folder/another_folder/image_name.png
.
I want to send this as a file using PHP curl I've doing this but it doesn't work
$ch = curl_init();
if (function_exists('curl_file_create')) { // php 5.5+
$cFile = curl_file_create('D:/folder/another_folder/image_name.png');
}else{
$cFile = '@' . realpath('D:/folder/another_folder/image_name.png');
}
$fields['userPhoto'] = $cFile;
$fields['uploadedfrom'] = 'web';
curl_setopt($ch, CURLOPT_URL, 'http://some_url.com');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
$result = curl_exec($ch);
curl_close($ch);
the issue is I'm getting the file path from a csv file not browsing it
Can anyone help with this and tell me how to send a file through PHP CURL from a string?