從 iPhone 上傳圖片會去除 exif 數據
2023-05-21
php問題
html5模板網
Image upload from iPhone strips exif data(從 iPhone 上傳圖片會去除 exif 數據)
本文介紹了從 iPhone 上傳圖片會去除 exif 數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我建立了一個允許上傳圖片的網站,一旦上傳圖片,就會顯示有關照片的一些特定信息.從計算機上傳圖片工作正常,當我嘗試從智能手機上傳圖片時出現問題.上傳成功,但從電腦上傳時顯示的數據似乎有很大一部分現在丟失了.
此代碼部分是實際檢索和顯示數據的部分:
$location = $_FILES["pic"]["tmp_name"];$data = exif_read_data($location);var_dump($data);
var_dump($data)
實際上在計算機和智能手機中轉儲不同的數據.
顯然它在 Android 智能手機上運行良好,只有當我嘗試從 iPhone 上傳圖像時才會出現問題. 例如,從計算機 上傳的var_dump
:
array(49) {[文件名"]=>字符串(10)php2D4.tmp"[文件日期時間"]=>整數(1367318152)[文件大小"]=>整數(30357)[文件類型"]=>整數(2)["MimeType"]=>字符串(10)圖像/jpeg"["SectionsFound"]=>字符串(24)ANY_TAG,IFD0,EXIF,GPS"[計算"]=>數組(6){[html"]=>字符串(24)寬度=320"高度=240"[高度"]=>整數(240)[寬度"]=>整數(320)[IsColor"]=>整數(1)[ByteOrderMotorola"]=>整數(1)[ApertureFNumber"]=>字符串(5)f/2.8"}[制作"]=>字符串(5)蘋果"[模型"]=>字符串(8)iPhone 4"[方向"]=>整數(3)[X分辨率"]=>字符串(4)72/1"[Y分辨率"]=>字符串(4)72/1"[分辨率單位"]=>整數(2)[軟件"]=>字符串(5)6.1.3"[日期時間"]=>字符串(19)2013:04:26 23:57:43"[YCbCrPositioning"]=>整數(1)[Exif_IFD_Pointer"]=>整數(204)[GPS_IFD_指針"]=>整數(594)[曝光時間"]=>字符串(4)1/15"[F號碼"]=>字符串(4)14/5"[曝光程序"]=>整數(2)[ISOSpeedRatings"]=>整數(1000)["ExifVersion"]=>字符串(4)0221"["DateTimeOriginal"]=>字符串(19)2013:04:26 23:57:43"[日期時間數字化"]=>字符串(19)2013:04:26 23:57:43"[組件配置"]=>字符串(4)"[快門速度值"]=>字符串(9)4889/1250"[光圈值"]=>字符串(9)4281/1441"[亮度值"]=>字符串(10)-3581/1451"[計量模式"]=>整數(5)[閃光"]=>整數(24)[焦距"]=>字符串(5)77/20"[主題位置"]=>數組(4){[0]=>整數(1295)[1]=>內部(967)[2]=>整數(699)[3]=>整數(696)}["FlashPixVersion"]=>字符串(4)0100"[色彩空間"]=>整數(1)["ExifImageWidth"]=>整數(2592)[ExifImageLength"]=>整數(1936)[傳感方法"]=>整數(2)[曝光模式"]=>整數(0)[白平衡"]=>整數(0)["FocalLengthIn35mmFilm"]=>整數(35)["SceneCaptureType"]=>整數(0)[GPSLatitudeRef"]=>字符串(1)N"[GPS緯度"]=>數組(3){[0]=>字符串(4)31/1"[1]=>字符串(8)5854/100"[2]=>字符串(3)0/1"}[GPSLongitudeRef"]=>字符串(1)E"[GPS經度"]=>數組(3){[0]=>字符串(4)34/1"[1]=>字符串(8)4684/100"[2]=>字符串(3)0/1"}[GPSTimeStamp"]=>數組(3){[0]=>字符串(4)20/1"[1]=>字符串(4)57/1"[2]=>字符串(8)4272/100"}[GPSImgDirectionRef"]=>字符串(1)T"[GPSImgDirection"]=>字符串(9)48089/465"}
var_dump
來自智能手機 上傳:
array(12) {[文件名"]=>字符串(9)phpSzwfPw"[文件日期時間"]=>整數(1367318054)[文件大小"]=>整數(1778041)[文件類型"]=>整數(2)["MimeType"]=>字符串(10)圖像/jpeg"["SectionsFound"]=>字符串(19)ANY_TAG,IFD0,EXIF"[計算"]=>數組(5){[html"]=>字符串(26)寬度="2592高度="1936"[高度"]=>整數(1936)[寬度"]=>整數(2592)[IsColor"]=>整數(1)[ByteOrderMotorola"]=>整數(1)}[方向"]=>整數(3)[Exif_IFD_Pointer"]=>整數(38)[色彩空間"]=>整數(1)["ExifImageWidth"]=>整數(2592)[ExifImageLength"]=>整數(1936)}
這是計算機 var_dump($_FILES)
:
數組(1){ [圖片"]=>數組(5){ [姓名"]=>字符串(18)leaf2.JPG"[類型"]=>字符串(10)圖像/jpeg"[tmp_name"]=>字符串(14)/tmp/phpzeDUs9"[錯誤"]=>整數(0)[尺寸"]=>int(46439) } }
這是 iPhone 結果 var_dump($_FILES)
:
array(1) { ["pic"]=>數組(5){ [姓名"]=>字符串(9)圖像.jpg"[類型"]=>字符串(10)圖像/jpeg"[tmp_name"]=>字符串(14)/tmp/phplPUZky"[錯誤"]=>int(0) [大小"]=>整數(1455577)} }
這是上傳表單的 HTML 代碼:
</表單>
可能是什么原因造成的?
解決方案
問題
iphone(ipad 等,從現在起我就稱它為 iphone)是正確的,它會剝離 exif 數據.這也不是 iphone 上的錯誤,而是一個功能.
android 用戶不喜歡 iphone 和 iphone 用戶不喜歡 androids 的主要原因之一是因為 iphone 非常有限(在更改、更改等方面的自由).您不能只運行下載的應用程序、對設置的訪問受限等.
這是因為蘋果的策略是打造故障安全產品.如果你不能做奇怪的事情,就不會發生奇怪的事情".它試圖以各種可以想象的方式保護用戶.它還可以在上傳圖像時保護用戶.在 exif 中可能存在會損害用戶隱私的數據.諸如 GPS 坐標之類的東西,但即使是時間戳也會傷害用戶(想象一下,您上傳??帶有時間戳的海灘圖片,這是從您向老板報告生病那一刻起的).
所以基本上剝離所有 exif 數據是一種安全措施.我自己和其他很多人都不同意這個策略,但不幸的是,我們對此無能為力.
解決辦法
更新:這不起作用 .(感謝likeitlikeit 提供此信息)
幸運的是,您可以解決這個問題.Javascript 來拯救了.使用 javascript,您可以讀取 exif 數據并通過添加一些額外的 POST 數據將其與您的照片一起發送.
請注意 :此解決方案是由另一位開發人員提供給我的,尚未經過測試.
來源
您要求的是可靠的消息來源.不幸的是,它們很難找到,因為蘋果不像往常那樣說話,因此我掌握的所有信息都是道聽途說.
也許我可以提供的更可靠的消息來源之一是 flickr 工作人員之一,他確認根本原因是移動 safari 刪除了 exif.http://www.flickr.com/help/forum/en-我們/72157632100391901/#reply72157632135956813
I've built a website which allows image uploading and once an image is uploaded , some specific information about the photo is displayed.
Uploading pictures from computers works just fine , the problem comes up when I'm trying to upload an image from a smartphone. The upload success but it seems like a major part of the data that is displayed when uploading from computer is now missing.
This code section is the one that actually retrieves and display the data :
$location = $_FILES["pic"]["tmp_name"];
$data = exif_read_data($location);
var_dump($data);
the var_dump($data)
actually dumps different data in computers and smartphones.
Apparently it works just fine with Android smartphones, the problem only comes up when I try to upload images from iPhone.
For example, var_dump
from computer upload :
array(49) {
["FileName"]=> string(10) "php2D4.tmp"
["FileDateTime"]=> int(1367318152)
["FileSize"]=> int(30357)
["FileType"]=> int(2)
["MimeType"]=> string(10) "image/jpeg"
["SectionsFound"]=> string(24) "ANY_TAG, IFD0, EXIF, GPS"
["COMPUTED"]=> array(6) {
["html"]=> string(24) "width="320" height="240""
["Height"]=> int(240)
["Width"]=> int(320)
["IsColor"]=> int(1)
["ByteOrderMotorola"]=> int(1)
["ApertureFNumber"]=> string(5) "f/2.8"
}
["Make"]=> string(5) "Apple"
["Model"]=> string(8) "iPhone 4"
["Orientation"]=> int(3)
["XResolution"]=> string(4) "72/1"
["YResolution"]=> string(4) "72/1"
["ResolutionUnit"]=> int(2)
["Software"]=> string(5) "6.1.3"
["DateTime"]=> string(19) "2013:04:26 23:57:43"
["YCbCrPositioning"]=> int(1)
["Exif_IFD_Pointer"]=> int(204)
["GPS_IFD_Pointer"]=> int(594)
["ExposureTime"]=> string(4) "1/15"
["FNumber"]=> string(4) "14/5"
["ExposureProgram"]=> int(2)
["ISOSpeedRatings"]=> int(1000)
["ExifVersion"]=> string(4) "0221"
["DateTimeOriginal"]=> string(19) "2013:04:26 23:57:43"
["DateTimeDigitized"]=> string(19) "2013:04:26 23:57:43"
["ComponentsConfiguration"]=> string(4) ""
["ShutterSpeedValue"]=> string(9) "4889/1250"
["ApertureValue"]=> string(9) "4281/1441"
["BrightnessValue"]=> string(10) "-3581/1451"
["MeteringMode"]=> int(5)
["Flash"]=> int(24)
["FocalLength"]=> string(5) "77/20"
["SubjectLocation"]=> array(4) {
[0]=> int(1295)
[1]=> int(967)
[2]=> int(699)
[3]=> int(696)
}
["FlashPixVersion"]=> string(4) "0100"
["ColorSpace"]=> int(1)
["ExifImageWidth"]=> int(2592)
["ExifImageLength"]=> int(1936)
["SensingMethod"]=> int(2)
["ExposureMode"]=> int(0)
["WhiteBalance"]=> int(0)
["FocalLengthIn35mmFilm"]=> int(35)
["SceneCaptureType"]=> int(0)
["GPSLatitudeRef"]=> string(1) "N"
["GPSLatitude"]=> array(3) {
[0]=> string(4) "31/1"
[1]=> string(8) "5854/100"
[2]=> string(3) "0/1"
}
["GPSLongitudeRef"]=> string(1) "E"
["GPSLongitude"]=> array(3) {
[0]=> string(4) "34/1"
[1]=> string(8) "4684/100"
[2]=> string(3) "0/1"
}
["GPSTimeStamp"]=> array(3) {
[0]=> string(4) "20/1"
[1]=> string(4) "57/1"
[2]=> string(8) "4272/100"
}
["GPSImgDirectionRef"]=> string(1) "T"
["GPSImgDirection"]=> string(9) "48089/465"
}
var_dump
from smartphone upload:
array(12) {
["FileName"]=> string(9) "phpSzwfPw"
["FileDateTime"]=> int(1367318054)
["FileSize"]=> int(1778041)
["FileType"]=> int(2)
["MimeType"]=> string(10) "image/jpeg"
["SectionsFound"]=> string(19) "ANY_TAG, IFD0, EXIF"
["COMPUTED"]=> array(5) {
["html"]=> string(26) "width="2592" height="1936""
["Height"]=> int(1936)
["Width"]=> int(2592)
["IsColor"]=> int(1)
["ByteOrderMotorola"]=> int(1)
}
["Orientation"]=> int(3)
["Exif_IFD_Pointer"]=> int(38)
["ColorSpace"]=> int(1)
["ExifImageWidth"]=> int(2592)
["ExifImageLength"]=> int(1936)
}
Here's the computer var_dump($_FILES)
:
array(1)
{ ["pic"]=> array(5)
{ ["name"]=> string(18) leaf2.JPG"
["type"]=> string(10) "image/jpeg"
["tmp_name"]=> string(14) "/tmp/phpzeDUs9"
["error"]=> int(0)
["size"]=> int(46439) } }
Here's the iPhone results var_dump($_FILES)
:
array(1) { ["pic"]=> array(5)
{ ["name"]=> string(9) "image.jpg"
["type"]=> string(10) "image/jpeg"
["tmp_name"]=> string(14) "/tmp/phplPUZky"
["error"]=> int(0) ["size"]=> int(1455577) } }
EDIT : Here is the uploading form HTML code:
<form action="results.php" id="upload-image" method="post" enctype="multipart/form-data">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;"></div>
<div>
<span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="pic" id="pic" accept="image/*"/></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
<button type="submit" class="btn">Upload</button>
</br>
<span class="upload-error"></span>
</div>
</form>
What might cause it?
解決方案
The problem
It is correct that the iphone(ipad, etc, i'll just call it iphone from now on) strips exif data. This is also not a bug on the iphone but actually a feature.
One of the main reasons android users don't like the iphone and iphone users don't like the androids, is because the iphone is very limited (in terms of freedom to change, alter, etc). You can not just run downloaded apps, have limited access to settings, etc.
This is because the apple strategy is to create a fail-safe product. "If you can not do strange things, strange things will not happen".It tries to protect the user in every way imaginable. It also protects the user when uploading images. In the exif there may be data that can hurt the users privacy. Things like GPS coordinates, but even a timestamp can hurt a user (imagine you uploading a beach picture with a timestamp from a moment you reported in sick with the boss).
So basically it is a safety meassure to strip all exif data. Myself and a lot of other people do not agree with this strategy, but there is nothing we can do about it unfortunately.
The solution
Update: This does not work . (thanks likeitlikeit for this info)
Luckily you can get around this problem. Javascript comes to the rescue. With javascript you can read the exif data and send it with you photo by adding some extra POST data.
please note : this solution was presented to me by another developer and is not yet tested.
Sources
You are asking for credible sources. Unfortunately they are hard to find as apple is not talking as always and therefore all information i have is hearsay.
perhaps one of the more reliable sources i can present is one of the flickr staffmembers who confirms that the root cause is mobile safari stripping the exif.
http://www.flickr.com/help/forum/en-us/72157632100391901/#reply72157632135956813
這篇關于從 iPhone 上傳圖片會去除 exif 數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!