I download an image by cURL on KOBO Collect server.
The download is fine, however it overwrites the exif data in the image.
I use Code Igniter 4.
I would like to get the exif data contained in the image before or after the download, with PHP or javascript.
This data must be stored in my database (gps etc)
My code :
public function test()
{
$client = \Config\Services::curlrequest();
$kobo_url = 'https://kc.humanitarianresponse.infoxxxxxx.png';
$response = $client->request('GET',$kobo_url , [
'auth' => ['user', 'My Password'] ]);
//echo $response->getStatusCode();
$resultat = $response->getBody();
$img_path = './assets/images/kobo/test.png';
$fp = fopen($img_path, 'x');
fwrite($fp, $resultat);
fclose($fp);
$exif = exif_read_data($resultat);
var_dump ($exif);
}
Thanks.
My Answer:
To get the exif data from an image using cURL in PHP, you can use the exif_read_data function. However, in your code, you are trying to read the exif data from the response body directly, which may not work as the exif data is stored in the image file itself.
Here's an updated version of your code that saves the image to a file and then reads the exif data from that file:
php
public function test()
{
$client = \Config\Services::curlrequest();
$kobo_url = 'https://kc.humanitarianresponse.infoxxxxxx.png';
$response = $client->request('GET', $kobo_url, [
'auth' => ['user', 'My Password']
]);
$resultat = $response->getBody();
$img_path = './assets/images/kobo/test.png';
$fp = fopen($img_path, 'x');
fwrite($fp, $resultat);
fclose($fp);
$exif = exif_read_data($img_path);
var_dump($exif);
}
In this code, we save the image content to a file using fwrite, and then we read the exif data from that file using exif_read_data. The exif data will be stored in the $exif variable, which you can then store in your database as needed.
Make sure to have the exif extension enabled in your PHP configuration for this to work. You can check if the exif extension is enabled by running phpinfo() and looking for the exif section.
Rate this post
5 of 5 based on 4329 votesComments