0

I'm trying to read the MimeType in the computed headers of EXIF read data but can't seem to find it, instead my loop just var dumps as if it can't find it but upon looking through the vardump i can see that Thumbnail.MimeType is indeed in the computed headers and I may be just trying to access it wrong, see code below, it accepts image upload and then uploads to a s3 bucket then I get the headers using the bucket image url.

$result = $s3->putObject([
    'Bucket' => '*********',
    'Key' => 'full/' . $file_name,
    'SourceFile' => $temp_file_location,
    'ACL' => 'public-read'
]);

$code = $result['@metadata']['statusCode'];
if ($code === 200) {
    $path = "url";
}
$exif_headers = exif_read_data($path, 'EXIF');
$computed_headers = exif_read_data($path, 'COMPUTED');

//check if image has datetime original.
if (!empty($exif_headers['DateTimeOriginal'])) {
    $exif_date = $exif_headers['DateTimeOriginal'];
    echo $exif_date;
} else {
    // if no date time original pull Thumbnail.MimeType.
    if (!empty($computed_headers['Thumbnail.MimeType'])) {
        $exif_mime_type = $computed_headers['Thumbnail.MimeType'];
        echo $exif_mime_type;
    } else { // var dump if Thumbnail.MimeType is empty.
        var_dump($computed_headers);
    }
}

any help would be greatly appreciated :), I feel like i am just missing something as i'm able to pull DateTimeOriginal when it is present without issues. TIA

Edit: here is the var dump

array(21) { 
    ["FileName"]=> string(67) "5dce8027494055dce756d6bce615ACDD56-0BF6-4754- 
    BA08-C5FD4E0C38EC.jpeg" 
    ["FileDateTime"]=> int(0) 
    ["FileSize"]=> int(1309255) 
    ["FileType"]=> int(2) 
    ["MimeType"]=> string(10) "image/jpeg" 
    ["SectionsFound"]=> string(30) "ANY_TAG, IFD0, THUMBNAIL, EXIF" 

    ["COMPUTED"]=> array(7) { 
    ["html"]=> string(26) "width="3264" height="2448"" 
    ["Height"]=> int(2448) 
    ["Width"]=> int(3264) 
    ["IsColor"]=> int(1) 
    ["ByteOrderMotorola"]=> int(1) 
    ["Thumbnail.FileType"]=> int(2) 
    ["Thumbnail.MimeType"]=> string(10) "image/jpeg" } 
    ["Orientation"]=> int(1) 
    ["XResolution"]=> string(4) "72/1" 
    ["YResolution"]=> string(4) "72/1" 
    ["ResolutionUnit"]=> int(2) 
    ["YCbCrPositioning"]=> int(1) 
    ["Exif_IFD_Pointer"]=> int(102) 


["THUMBNAIL"]=> array(6) { 
    ["Compression"]=> int(6) 
    ["XResolution"]=> string(4) "72/1" 
    ["YResolution"]=> string(4) "72/1" 
    ["ResolutionUnit"]=> int(2) 
    ["JPEGInterchangeFormat"]=> int(286) 
    ["JPEGInterchangeFormatLength"]=> int(7063)
} 

    ["ExifVersion"]=> string(4) "0221" 
    ["ComponentsConfiguration"]=> string(4) "" 
    ["FlashPixVersion"]=> string(4) "0100" 
    ["ColorSpace"]=> int(1) 
    ["ExifImageWidth"]=> int(3264) 
    ["ExifImageLength"]=> int(2448) 
    ["SceneCaptureType"]=> int(0) 
}
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • You may want to attach the mentioned vardump. – YellowAfterlife Nov 15 '19 at 10:32
  • just added the vardump totally forgot about it originally :) – Sean Pattinson Nov 15 '19 at 10:39
  • Please present the dump properly formatted, as just one long tangled mass of text this is hardly readable, and it is hard to figure out the actual structure. – 04FS Nov 15 '19 at 10:49
  • Thumbnail.MimeType is inside the COMPUTED sub-object, it's not top-level. As the other person pointed out, this would have been more obvious if vardump was well-formatted (take [a look into that](https://stackoverflow.com/a/19816742/5578773) for future) – YellowAfterlife Nov 15 '19 at 10:53
  • apologies on the formatting it's pretty much my first post on SO, so basically I need to access the COMPUTED sub-object and pull it from there and that is my issue if my understanding is correct? – Sean Pattinson Nov 15 '19 at 10:58
  • yep that works like a dream, thanks for the help guys also again apologies on the formatting :) – Sean Pattinson Nov 15 '19 at 11:07

1 Answers1

1

As stated in the PHP documentation the second parameter in the function call exif_read_data() represent a (comma seperated) list of sections that need to be present in file to produce a result array.

This means not that the function call will return aonly this section as result!

Change your code as below and it will work:

<?php
$result = $s3->putObject([
    'Bucket' => '*********',
    'Key' => 'full/' . $file_name,
    'SourceFile' => $temp_file_location,
    'ACL' => 'public-read'
]);

$code = $result['@metadata']['statusCode'];
if ($code === 200) {
    $path = "url";
}
$exif_data = exif_read_data($path, 'EXIF');
$computed_data = $exif_data['COMPUTED'];

//check if image has datetime original.
if (!empty($exif_data['DateTimeOriginal'])) {
    $exif_date = $exif_data['DateTimeOriginal'];
    echo $exif_date;
} else {
    // if no date time original pull Thumbnail.MimeType.
    if (!empty($computed_data['Thumbnail.MimeType'])) {
        $exif_mime_type = $computed_data['Thumbnail.MimeType'];
        echo $exif_mime_type;
    } else { // var dump if Thumbnail.MimeType is empty.
        var_dump($computed_data);
    }
}
?>
CodyKL
  • 1,024
  • 6
  • 14
  • This works thanks, also had this: $exif_mime_type = $computed_headers['COMPUTED']['Thumbnail.MimeType'] which worked thanks to 04FS – Sean Pattinson Nov 15 '19 at 11:52