Skip to content
Advertisement

How to get image exif data via cURL PHP

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 = ConfigServices::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.

Advertisement

Answer

I finally found a solution. By using “copy” the exif data is not altered. Also insert username and password in url far auth.

$file = 'https://user:password@kc.humanitarianresponse.info/media/original?media_file=xxxxx.jpg';
        $newfile = 'images.jpg';
        
        if ( copy($file, $newfile) ) {
            echo "Copy success!";
        }else{
            echo "Copy failed.";
        }

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement