Problems with cURL using Face ++

2

I'm using a Face ++ API for face recognition.

I put a code in PHP that sends a face.jpg to their API according to the rules in the documentation, but this cURL either is not sending the data or it is not working, because in Linux in shell_exec it works.

When trying to transfer the code to PHP it did not work.

My Linux code that works:

curl -X POST "https://api-us.faceplusplus.com/facepp/v3/detect" -F "api_key=<api_key>" \
-F "api_secret=<api_secret>" \
-F "image_file=@image_file.jpg" \
-F "return_landmark=1" \
-F "return_attributes=gender,age"

My code in PHP that does not bring me back:

$data = array(
    'api_key' => '<APIKEYAKI>', 
    'api_secret' => '<SECRETAKI>',
    'return_landmark' => '1',
    'return_attributes' => 'gender,age'
);   

$data['image_file'] = '@./jasar.jpg';

$handle = curl_init('https://api-us.faceplusplus.com/facepp/v3/search');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
$dados = curl_exec($handle);
curl_close($handle);

echo $dados;

already tried changing PHP codes; I got several examples right here on the site and nothing.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api-us.faceplusplus.com/facepp/v3/search");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "api_key=123456&api_secret=32164&return_attributes=gender,age&outer_id=facesetpocface&image_file=@".realpath('jasar.jpg'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);


print($result);
    
asked by anonymous 09.08.2018 / 17:02

1 answer

2

Try this way and tell me if it worked

$handle = curl_init('https://api-us.faceplusplus.com/facepp/v3/search');
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array(
    'api_key' => '<APIKEYAKI>', 
    'api_secret' => '<SECRETAKI>',
    'image_file' => curl_file_create(realpath('marquito.jpg')),   
    'return_landmark' => '1',
    'return_attributes' => 'gender,age'
));
$dados = curl_exec($handle);
curl_close($handle);

echo $dados;
    
10.08.2018 / 19:12