duanniling0018 2013-04-18 13:27
浏览 73
已采纳

在移动设备上使用PHP上传图片时剥离GPS标题?

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("[...]");?>
  • 写回答

1条回答 默认 最新

  • duanji1902 2014-06-28 20:37
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题