当上传图片与移动设备上的PHP剥离GPS头? [英] exif when uploading pictures with php on a mobile device stripping GPS header?

查看:207
本文介绍了当上传图片与移动设备上的PHP剥离GPS头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本将照片上传到用PHP编写的网站。当我在iPhone上使用Safari上传图片时,当检查exif数据时,某些标题似乎被剥离。当我从我的iPhone上采取完全相同的照片,并通过电子邮件发送给我自己,并从计算机上传时,所有的exif数据都在那里。



我想知道是否有一个iPhone或PHP脚本的设置,我错过了,当我尝试上传时,会让我抓住exif的GPS部分从我的iPhone。我只想从exif_read_data获取GPS数据,当我通过iPhone上传图片到我的网站时。



来自Iphone上的Safari的一个Exif例子:

 图像类型为:JPEG 

FILE.FileName:20130417141031image.jpg
FILE.FileDateTime:1366225831
FILE.FileSize:1692449
FILE.FileType:2
FILE.MimeType:image / jpeg
FILE.SectionsFound:ANY_TAG,IFD0,EXIF
COMPUTED.html: width =3264height =2448
COMPUTED.Height:2448
COMPUTED.Width:3264
COMPUTED.IsColor:1
COMPUTED.ByteOrderMotorola:1
IFD0.Orientation:6
IFD0.Exif_IFD_Pointer:38
EXIF.ColorSpace:1
EXIF.ExifImageWidth:3264
EXIF.ExifImageLength:2448



从我的电脑上传的同一个图像的同一个图像的一个Exif例子:

 图像类型是:JPEG 

FILE.FileName:20130417142504image.jpeg
FILE.FileDateTime:1366226835
FILE.FileSiz e:1744896
FILE.FileType:2
FILE.MimeType:image / jpeg
FILE.SectionsFound:ANY_TAG,IFD0,THUMBNAIL,EXIF,GPS
COMPUTED.html:width = 3264height =2448
COMPUTED.Height:2448
COMPUTED.Width:3264
COMPUTED.IsColor:1
COMPUTED.ByteOrderMotorola:1
COMPUTED。 ApertureFNumber:f / 2.4
COMPUTED.Thumbnail.FileType:2
COMPUTED.Thumbnail.MimeType:image / jpeg
IFD0.Make:Apple
IFD0.Model:iPhone 4S
IFD0.Orientation:6
IFD0.XResolution:72/1
IFD0.YResolution:72/1
IFD0.ResolutionUnit:2
IFD0.Software:6.1.3
IFD0.DateTime:2013:04:17 15:13:39
IFD0.YCbCrPositioning:1
IFD0.Exif_IFD_Pointer:204
IFD0.GPS_IFD_Pointer:594
THUMBNAIL。压缩:6
THUMBNAIL.X分辨率:72/1
THUMBNAIL.Y分辨率:72/1
THUMBNAIL.ResolutionUnit:2
THUMBNAIL.JPEGInterchangeFormat:890
THUMBNAIL.JPEGInterchangeFormatLength :7684
EXIF.ExposureTime:1/20
EXIF.FNumber:12/5
EX IF.ExposureProgram:2
EXIF.ISOSpeedRatings:50
EXIF.ExifVersion:0221
EXIF.DateTimeOriginal:2013:04:17 15:13:39
EXIF.DateTimeDigitized:2013 :04:17 15:13:39
EXIF.ComponentsConfiguration:
EXIF.ShutterSpeedValue:2779/643
EXIF.ApertureValue:4845/1918
EXIF.BrightnessValue:13523/4727
EXIF.MeteringMode:3
EXIF.Flash:16
EXIF.FocalLength:107/25
EXIF.SubjectLocation:Array
EXIF.FlashPixVersion:0100
EXIF.ColorSpace:1
EXIF.ExifImageWidth:3264
EXIF.ExifImageLength:2448
EXIF.SensingMethod:2
EXIF.ExposureMode:0
EXIF.Wh​​iteBalance: 0
EXIF.FocalLengthIn35mmFilm:35
EXIF.SceneCaptureType:0
GPS.GPSLatitudeRef:N
GPS.GPSLatitude:Array
GPS.GPSLongitudeRef:W
GPS.GPSLongitude:Array
GPS.GPSAltitudeRef:
GPS.GPSAltitude:55556/297
GPS.GPSTimeStamp:Array
GPS.GPSImgDirectionRef:T
GPS.GPSImgDirection: 19688/145

她e是我用于我的PHP脚本照片的代码,我删除了标题,并要求:

 <?php 
require('[...]');
mysql_select_db($ db_name,$ oConn);

$ JobNum = $ _POST ['JobNum']; ($($ _FILES [file] [type] ==image / gif)
$($ _FILES [file] [type ]
($ _FILES [file] [type] ==image / pjpeg))
&&($ _FILES [文件] [size]< 10000000))
{
if($ _FILES [file] [error]> 0)
{
ps_log (Bad Photo Upload - Return Code:。$ _FILES [file] [error]);


{
ps_log(Upload:。$ _FILES [file] [name]);
ps_log(Type:。$ _FILES [file] [type]);
ps_log(Size:。($ _FILES [file] [size] / 1024)。Kb);
ps_log(Temp file:。$ _FILES [file] [tmp_name]。< br />);

$ photoname = $ _FILES ['file'] ['tmp_name'];
$ root =[...];
$ location = $ _SERVER ['DOCUMENT_ROOT']。$ root。$ photoname;
$ exif = exif_read_data($ photoname,0,true);

$ filename = $ exif [FILE] [FileName];
$ model = $ exif [IFD0] [Model];
$ date = $ exif [IFD0] [DateTime];
$ lon = $ exif [GPS] [GPSLongitude];
$ lonref = $ exif [GPS] ['GPSLongitudeRef'];
$ lat = $ exif [GPS] [GPSLatitude];
$ latref = $ exif [GPS] ['GPSLatitudeRef'];


$ lon = Photos :: getGps($ lon,$ lonref);
$ lat = Photos :: getGps($ lat,$ latref);

$ photo = new UploadedPhoto();
$ photo-> JobNum = $ JobNum;
$ photo-> TempFile = $ _FILES [file] [tmp_name];
$ photo-> FileName = $ _FILES [file] [name];
$ photo->评论= $ _POST ['Comment'];
$ photo-> Model = $ model;
$ photo-> DateStamp = $ date;
$ photo-> Lat = $ lat;
$ photo-> Lng = $ lon;
$ photo-> SaveGeo();


else

echoInvalid file;
}

header([...]);?>


解决方案

唯一可以做的就是创建一个原生应用程序(或Apache Cordova应用程序),将处理上传。 GPS数据被移动Safari剥离。你的应用程序应该照原样上传图片。到目前为止,没有其他办法。

可能是这样的: http://gonzalo123.com/2013/10/28/taking-photos-with-a-phonegapcordova-application-and -uploading-them-to-the-server /


I have a script to upload photos to a website written in PHP. When I upload a picture using Safari on my IPhone, some of the header appears to be stripped when I check the exif data. When I take the exact same picture from my IPhone and email it to myself and upload it from a computer, all of the exif data is there.

I was wondering if there was a setting on the IPhone or a PHP script that I am missing that will let me grab the GPS part of the exif when I try to upload from my IPhone. All I want is to grab the GPS array from the exif_read_data when I upload pictures to my website through my IPhone.

An Exif example from my Safari on Iphone:

Image type is: JPEG

FILE.FileName: 20130417141031image.jpg
FILE.FileDateTime: 1366225831
FILE.FileSize: 1692449
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, EXIF
COMPUTED.html: width="3264" height="2448"
COMPUTED.Height: 2448
COMPUTED.Width: 3264
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
IFD0.Orientation: 6
IFD0.Exif_IFD_Pointer: 38
EXIF.ColorSpace: 1
EXIF.ExifImageWidth: 3264
EXIF.ExifImageLength: 2448

An Exif example of the same image uploaded from my PC taken by the same phone:

Image type is: JPEG

FILE.FileName: 20130417142504image.jpeg
FILE.FileDateTime: 1366226835
FILE.FileSize: 1744896
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
COMPUTED.html: width="3264" height="2448"
COMPUTED.Height: 2448
COMPUTED.Width: 3264
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.ApertureFNumber: f/2.4
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
IFD0.Make: Apple
IFD0.Model: iPhone 4S
IFD0.Orientation: 6
IFD0.XResolution: 72/1
IFD0.YResolution: 72/1
IFD0.ResolutionUnit: 2
IFD0.Software: 6.1.3
IFD0.DateTime: 2013:04:17 15:13:39
IFD0.YCbCrPositioning: 1
IFD0.Exif_IFD_Pointer: 204
IFD0.GPS_IFD_Pointer: 594
THUMBNAIL.Compression: 6
THUMBNAIL.XResolution: 72/1
THUMBNAIL.YResolution: 72/1
THUMBNAIL.ResolutionUnit: 2
THUMBNAIL.JPEGInterchangeFormat: 890
THUMBNAIL.JPEGInterchangeFormatLength: 7684
EXIF.ExposureTime: 1/20
EXIF.FNumber: 12/5
EXIF.ExposureProgram: 2
EXIF.ISOSpeedRatings: 50
EXIF.ExifVersion: 0221
EXIF.DateTimeOriginal: 2013:04:17 15:13:39
EXIF.DateTimeDigitized: 2013:04:17 15:13:39
EXIF.ComponentsConfiguration: 
EXIF.ShutterSpeedValue: 2779/643
EXIF.ApertureValue: 4845/1918
EXIF.BrightnessValue: 13523/4727
EXIF.MeteringMode: 3
EXIF.Flash: 16
EXIF.FocalLength: 107/25
EXIF.SubjectLocation: Array
EXIF.FlashPixVersion: 0100
EXIF.ColorSpace: 1
EXIF.ExifImageWidth: 3264
EXIF.ExifImageLength: 2448
EXIF.SensingMethod: 2
EXIF.ExposureMode: 0
EXIF.WhiteBalance: 0
EXIF.FocalLengthIn35mmFilm: 35
EXIF.SceneCaptureType: 0
GPS.GPSLatitudeRef: N
GPS.GPSLatitude: Array
GPS.GPSLongitudeRef: W
GPS.GPSLongitude: Array
GPS.GPSAltitudeRef: 
GPS.GPSAltitude: 55556/297
GPS.GPSTimeStamp: Array
GPS.GPSImgDirectionRef: T
GPS.GPSImgDirection: 19688/145

Here is the code that I use for my PHP script for photos, I removed the header and requires:

<?php
require('[...]');
mysql_select_db($db_name, $oConn);

$JobNum = $_POST['JobNum'];

if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 10000000))
{
    if ($_FILES["file"]["error"] > 0)
    {
        ps_log( "Bad Photo Upload - Return Code: " . $_FILES["file"]["error"]);
    }
    else
    {
        ps_log( "Upload: " . $_FILES["file"]["name"]);
        ps_log( "Type: " . $_FILES["file"]["type"]);
        ps_log( "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb");
        ps_log( "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />");

        $photoname = $_FILES['file']['tmp_name'];
        $root = "[...]";
        $location = $_SERVER['DOCUMENT_ROOT'].$root.$photoname;
        $exif = exif_read_data($photoname, 0, true);

        $filename = $exif["FILE"]["FileName"];
        $model = $exif["IFD0"]["Model"];
        $date = $exif["IFD0"]["DateTime"];
        $lon = $exif["GPS"]["GPSLongitude"];
        $lonref = $exif["GPS"]['GPSLongitudeRef'];
        $lat = $exif["GPS"]["GPSLatitude"];
        $latref = $exif["GPS"]['GPSLatitudeRef'];


        $lon = Photos::getGps($lon, $lonref);
        $lat = Photos::getGps($lat, $latref);

        $photo = new UploadedPhoto();
        $photo->JobNum = $JobNum;
        $photo->TempFile = $_FILES["file"]["tmp_name"];
        $photo->FileName = $_FILES["file"]["name"];
        $photo->Comments = $_POST['Comment'];
          $photo->Model = $model ;
  $photo->DateStamp = $date ;
  $photo->Lat = $lat ;
  $photo->Lng = $lon ;
        $photo->SaveGeo();
    }
}
else
{
    echo "Invalid file";
}

header("[...]");?>

解决方案

Only thing you can do is to create a native app (or Apache Cordova app), that will handle the upload. The GPS data is stripped by mobile Safari. Your app should upload the picture as-is. As of now there is no other way around it.

It may be something along these lines: http://gonzalo123.com/2013/10/28/taking-photos-with-a-phonegapcordova-application-and-uploading-them-to-the-server/

这篇关于当上传图片与移动设备上的PHP剥离GPS头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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