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

在移动设备上使用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条回答 默认 最新

相关推荐 更多相似问题