从 iPhone 上传图片会去除 exif 数据 [英] Image upload from iPhone strips exif data

查看:60
本文介绍了从 iPhone 上传图片会去除 exif 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个允许上传图片的网站,一旦上传图片,就会显示有关照片的一些特定信息.从计算机上传图片工作正常,当我尝试从智能手机上传图片时出现问题.上传成功,但从电脑上传时显示的数据似乎有很大一部分现在丢失了.

此代码部分是实际检索和显示数据的部分:

$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 代码:

 
<div class="fileupload fileupload-new" data-provides="fileupload"><div class="fileupload-preview缩略图" style="width: 200px; height: 150px;"></div><div><span class="btn btn-file"><span class="fileupload-new">选择图片</span><span class="fileupload-exists">更改</span><input type="file" name="pic" id="pic" accept="image/*"/></span><a href="#" class="btn fileupload-exists" data-dismiss="fileupload">删除</a><button type="submit" class="btn">上传</button></br><span class="upload-error"></span>

</表单>

可能是什么原因造成的?

解决方案

问题

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 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆