从iphone上传图像exif数据

34 php iphone jquery exif file-upload

我已经建立了一个允许图像上传的网站,一旦上传图像,就会显示一些关于照片的特定信息.从计算机上传图片工作得很好,当我尝试从智能手机上传图像时出现问题.上传成功但似乎现在缺少从计算机上传时显示的数据的主要部分.

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

$location = $_FILES["pic"]["tmp_name"];
$data = exif_read_data($location);
var_dump($data);
Run Code Online (Sandbox Code Playgroud)

var_dump($data)实际转储电脑和智能手机不同的数据.

编辑:显然它与Andoroid智能手机一起工作得很好,当我尝试从iPhone上传图像时问题才会出现

例如,var_dump计算机上传:

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" 
}
Run Code Online (Sandbox Code Playgroud)

var_dump智能手机上传:

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) 
}
Run Code Online (Sandbox Code Playgroud)

这是电脑 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) } }
Run Code Online (Sandbox Code Playgroud)

这是iPhone的结果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) } } 
Run Code Online (Sandbox Code Playgroud)

编辑:这是上传表格HTML代码:

     <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>
Run Code Online (Sandbox Code Playgroud)

可能导致什么?

nva*_*sch 21

问题

iphone(ipad等,我从现在开始称之为iphone)正确剥离exif数据是正确的.这也不是iPhone的错误,但实际上是一个功能.

Android用户不喜欢iphone和iphone用户不喜欢机器人的主要原因之一是因为iPhone非常有限(在改变,改变等方面的自由度).您不能只运行下载的应用,限制访问设置等.

这是因为苹果策略是创建一个故障安全产品."如果你不能做出奇怪的事情,就不会发生奇怪的事情."它试图以各种可想象的方式保护用户.它还在上传图像时保护用户.在exif中,可能存在可能损害用户隐私的数据.诸如GPS坐标之类的东西,但即使是时间戳也会伤害用户(想象一下,从您向老板报告的那一刻起,上传带有时间戳的海滩图片).

因此,剥离所有exif数据基本上是一种安全措施.我自己和很多其他人都不同意这个策略,但不幸的是我们无能为力.

解决方案

更新:这不起作用.(感谢喜欢这个信息)

幸运的是,你可以解决这个问题.Javascript来救援.使用javascript,您可以通过添加一些额外的POST数据来阅读exif数据并将其与您的照片一起发送.

请注意:此解决方案是由另一位开发人员提供给我的,尚未经过测试.

来源

你在寻求可靠的消息来源.不幸的是,他们很难找到,因为苹果并不像往常一样说话,因此我所拥有的所有信息都是道听途说.

也许我可以提出的一个更可靠的来源是flickr的工作人员之一,他确认根本原因是移动safari剥离exif. http://www.flickr.com/help/forum/en-us/72157632100391901/#reply72157632135956813

  • 这个答案已经过时了。现在,如果上传的图像以“最兼容”格式保存,iOS 不会删除元数据。但是,如果图像以“高效”格式保存,iOS 会删除元数据。它正在即时转换为 JPG。 (2认同)

lik*_*eit 6

Apple没有关于此功能的官方声明,尽管有很多人甚至在Apple论坛上都在询问这个问题.实际上,从"网络"报道的内容来看,这不仅仅发生在iPhone上的Safari上传,也适用于通过电子邮件发送的附件.

然而,很明显有很多人受此影响.Flickr似乎是一个主要的受害者,但也有其他人.

幸运的是,现在有一些方法可以访问<input type="file">标签的原始文件数据.这允许您获取所需的EXIF信息,将其放入隐藏的表单字段,并将其与实际的文件上载一起发送.我从这个答案中改编了一个jsfiddle来展示我的意思:

看看.

更新:JavaScript没有任何帮助

这似乎不会对当前一代iOS设备的理想效果,为FileReaderAPI也只得到访问消毒版本的文件.

  • 只是为了添加我的2c - 我一直在使用https://github.com/jseidelin/exif-js来获取客户端的Javascript中的EXIF数据 - 这在Android上工作正常,而在iPhone上它似乎可以工作但是对于任何图片只返回基本的EXIF数据(颜色深度;分辨率),而不是更多.我正在使用fileReader.readAsArrayBuffer. (2认同)

小智 6

如果pic通过电子邮件从iphone发送并保存到mac,exif数据将被保留.如果通过IMage Capture将其复制到mac,则保留exif数据.仅当从摄像机角色上传到服务时,才会在上传时发送exif数据.