1

I'm trying to Get the gps lat and log from exif but I'm unable to access the index properly. Here's what the basic var_dump looks like:

array(7) { ["FILE"]=> array(6) { ["FileName"]=> string(12) "DSC00043.JPG" ["FileDateTime"]=> int(1481834862) ["FileSize"]=> int(4259986) ["FileType"]=> int(2) ["MimeType"]=> string(10) "image/jpeg" ["SectionsFound"]=> string(44) "ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP" } ["COMPUTED"]=> array(10) { ["html"]=> string(26) "width="6000" height="4000"" ["Height"]=> int(4000) ["Width"]=> int(6000) ["IsColor"]=> int(1) ["ByteOrderMotorola"]=> int(0) ["ApertureFNumber"]=> string(5) "f/5.6" ["UserComment"]=> NULL ["UserCommentEncoding"]=> string(5) "ASCII" ["Thumbnail.FileType"]=> int(2) ["Thumbnail.MimeType"]=> string(10) "image/jpeg" } ["IFD0"]=> array(13) { ["ImageDescription"]=> string(31) " " ["Make"]=> string(4) "SONY" ["Model"]=> string(9) "ILCE-6300" ["Orientation"]=> int(1) ["XResolution"]=> string(5) "350/1" ["YResolution"]=> string(5) "350/1" ["ResolutionUnit"]=> int(2) ["Software"]=> string(15) "ILCE-6300 v1.10" ["DateTime"]=> string(19) "2016:01:17 22:26:22" ["YCbCrPositioning"]=> int(2) ["Exif_IFD_Pointer"]=> int(8) ["GPS_IFD_Pointer"]=> int(47147) ["UndefinedTag:0xC4A5"]=> string(106) "PrintIM0300 " ' '� '� ' '^ '� '� '� '" } ["THUMBNAIL"]=> array(13) { ["Compression"]=> int(6) ["ImageDescription"]=> string(31) " " ["Make"]=> string(4) "SONY" ["Model"]=> string(9) "ILCE-6300" ["Orientation"]=> int(1) ["XResolution"]=> string(4) "72/1" ["YResolution"]=> string(4) "72/1" ["ResolutionUnit"]=> int(2) ["Software"]=> string(15) "ILCE-6300 v1.10" ["DateTime"]=> string(19) "2016:01:17 22:26:22" ["JPEGInterchangeFormat"]=> int(38350) ["JPEGInterchangeFormatLength"]=> int(8797) ["YCbCrPositioning"]=> int(2) } ["EXIF"]=> array(38) { ["ExposureTime"]=> string(6) "1/1000" ["FNumber"]=> string(5) "56/10" ["ExposureProgram"]=> int(1) ["ISOSpeedRatings"]=> int(1000) ["UndefinedTag:0x8830"]=> int(2) ["UndefinedTag:0x8832"]=> int(1000) ["ExifVersion"]=> string(4) "0230" ["DateTimeOriginal"]=> string(19) "2016:01:17 22:26:22" ["DateTimeDigitized"]=> string(19) "2016:01:17 22:26:22" ["ComponentsConfiguration"]=> string(4) " " ["CompressedBitsPerPixel"]=> string(3) "1/1" ["BrightnessValue"]=> string(10) "21294/2560" ["ExposureBiasValue"]=> string(4) "0/10" ["MaxApertureValue"]=> string(7) "760/256" ["MeteringMode"]=> int(5) ["LightSource"]=> int(0) ["Flash"]=> int(16) ["FocalLength"]=> string(6) "190/10" ["MakerNote"]=> string(9) "SONY DSC " ["UserComment"]=> string(64) "ASCII" ["FlashPixVersion"]=> string(4) "0100" ["ColorSpace"]=> int(1) ["ExifImageWidth"]=> int(6000) ["ExifImageLength"]=> int(4000) ["InteroperabilityOffset"]=> int(47385) ["FileSource"]=> string(1) " " ["SceneType"]=> string(1) " " ["CustomRendered"]=> int(0) ["ExposureMode"]=> int(1) ["WhiteBalance"]=> int(0) ["DigitalZoomRatio"]=> string(5) "16/16" ["FocalLengthIn35mmFilm"]=> int(28) ["SceneCaptureType"]=> int(0) ["Contrast"]=> int(0) ["Saturation"]=> int(0) ["Sharpness"]=> int(0) ["UndefinedTag:0xA432"]=> array(4) { [0]=> string(6) "190/10" [1]=> string(6) "190/10" [2]=> string(5) "28/10" [3]=> string(5) "28/10" } ["UndefinedTag:0xA434"]=> string(11) "E 19mm F2.8" } ["GPS"]=> array(6) { ["GPSVersion"]=> string(4) " " ["GPSLatitudeRef"]=> string(1) "N" ["GPSLatitude"]=> array(3) { [0]=> string(4) "34/1" [1]=> string(3) "5/1" [2]=> string(11) "231365/9853" } ["GPSLongitudeRef"]=> string(1) "W" ["GPSLongitude"]=> array(3) { [0]=> string(4) "83/1" [1]=> string(4) "59/1" [2]=> string(11) "100499/4849" } ["GPSAltitude"]=> string(12) "2219798/6091" } ["INTEROP"]=> array(2) { ["InterOperabilityIndex"]=> string(3) "R98" ["InterOperabilityVersion"]=> string(4) "0100" } }

I've been using this function just to get the my $exifs['FileName']; because it is also an unknown index if I were to just echo it out: I also try to access the gps array in this function.

public function get_data($files){
    $data = array();
    $name = '';
    foreach ($files as $file) {
        $exifs   = exif_read_data($file, 0, true);
        //var_dump($exifs);
        foreach ($exifs as $exif) {
            extract($exif);
            $name = $FileName;
            foreach ($GPS as $key) {
                echo $key;
                # code...
            }
            break;
        }
    }
    return $name;
}
Austin Mauldin
  • 315
  • 1
  • 6
  • 17
  • It's `$exifs['FILE']['FileName']` – Barmar Dec 16 '16 at 22:42
  • 1
    If you want more help, you need to post the `var_dump()` with decent indentation, so we can see the nesting level of everything. – Barmar Dec 16 '16 at 22:44
  • So $exifs['file path']['key'] would give me access to even array parameters? Sorry about the indentation I'm on mobile, I'll do my best to fix it. – Austin Mauldin Dec 16 '16 at 22:54
  • Use `echo '
    '; var_dump($exifs); echo '
    ';` to get PHP to display the formatted dump.
    – Barmar Dec 16 '16 at 22:56
  • When you have nested arrays, the syntax is `$array["outer key"]["inner key"]` – Barmar Dec 16 '16 at 22:57
  • A `json_encode()` version of `$exifs` would be much easier to test with. We can't run your code with manually converting the `var_dump()` output into a proper value that your script can work with... – Guillaume Boudreau Dec 16 '16 at 23:06

1 Answers1

0

You can simply access values from such an object by specifying the keys: $exifs['FILE']['FileName'] for example.

To get the filename, lat and lon values for all the files, you'd do something like:

public function get_data($files) {
    $data = array();
    foreach ($files as $file) {
        $exifs = exif_read_data($file, 0, true);
        $data[] = [
            'filename' => $exifs['FILE']['FileName'],
            'gps_lat' => $exifs['GPS']['GPSLatitude'],
            'gps_lon' => $exifs['GPS']['GPSLongitude'],
        ]
    }
    return $data;
}

Of note, the lat and lon values are kind of funky, not the 'usual' format. See this answer to transform the gps_lat and gps_lon values into floats.

Community
  • 1
  • 1
Guillaume Boudreau
  • 2,676
  • 29
  • 27