我正在尝试在EXIF的计算头中读取MimeType,但似乎无法找到它,相反,我的循环只是var dumps好像找不到它,但是通过查看vardump时,我可以看到Thumbnail.MimeType确实在计算的标头中,我可能只是想尝试访问它而已,请参见下面的代码,它接受图像上传,然后上传到s3存储桶,然后使用存储桶图像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);
}
}
任何帮助将不胜感激:),我觉得我只是想念某些东西,因为它能够在没有问题的情况下拉起DateTimeOriginal。 TIA
编辑:这是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)
}
如PHP documentation中所述,函数调用exif_read_data()中的第二个参数表示文件中必须存在以生成结果数组的部分的(逗号分隔)列表。
这并不意味着函数调用将仅返回此部分作为结果!
如下更改代码,它将起作用:
<?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);
}
}
?>