I'm trying to run CURL command in PHP to upload image to an API the code mentioned in the doc was:
curl -u 15:tokenkeyiskmzwa8awaa https://api.bukalapak.com/v2/images.json -F file=@product-image.png -X POST
Have tried using mac terminal running this curl command (with proper username and password) and successfully got the result as it is uploading, however was not successfully doing it on PHP. My php code is :
<?php
$data = array('file'=> '@'.$imagePath );
// this is an absolute path, give something like D://folder/path/on/my/webserver/image.jpg
$user = '1234567';
$pass = '123456';
$ch = curl_init();
$curl_options[CURLOPT_URL] = 'https://api.bukalapak.com/v2/images.json';
$curl_options[CURLOPT_CAINFO] = storage_path('app/cacert.pem');
$curl_options[CURLOPT_HEADER] = "Content-Type: application/x-www-form-urlencoded";
$curl_options[CURLOPT_POST] = 1;
$curl_options[CURLOPT_USERPWD] = $user.':'.$pass;
$curl_options[CURLOPT_POSTFIELDS] = http_build_query($data);
curl_setopt_array($ch, $curl_options);
$content = curl_exec($->ch);`
Curl version : 7.47.1 PHP version : 5.6.21 any feedback is very appreciated.