2015-09-20 157 views
1

所以我在玩read_exif_data函數,並遇到了一個小問題。 如果圖像沒有經緯度&,我必須停止文件上傳。檢查圖像中是否存在經度和緯度經度和緯度

問題是我找不到檢查gps數組是否在exif數據中的方法。

我正在讀取$ _ FILES ['spotImg'] ['tmp_name']的數據而且我確實得到了我的exif。

問題是隻有當圖像中沒有GPS數據時。

if($_FILES['spotImg']['error'] == 0){ 

      $file = "image_".uniqid(). $_FILES['spotImg']['name']; 
      $img = WideImage::loadFromFile($_FILES['spotImg']['tmp_name']); 

      //check if exif data is avalible 
      $temp = $_FILES['spotImg']['tmp_name']; 
      $exif = read_exif_data($temp, 0, true); 

      echo "<pre">; 
      print_r($exif); 
      echo "</pre>; 

} 

這是我在想什麼,但忽略了最低工作工作

if(isset($exif['GPSLatitude'])){ 
    //run code if long/latitude was found 
    }else{ 
    //give a error message if long/latitude was NOT found 
} 

這是我想檢查是否存在

[GPS] => Array 
    (
     [GPSLatitudeRef] => N 
     [GPSLatitude] => Array 
      (
       [0] => 55/1 
       [1] => 41/1 
       [2] => 2846/100 
      ) 

     [GPSLongitudeRef] => E 
     [GPSLongitude] => Array 
      (
       [0] => 12/1 
       [1] => 33/1 
       [2] => 1568/100 
      ) 

     [GPSAltitudeRef] => 
     [GPSAltitude] => 68780/4027 
     [GPSTimeStamp] => Array 
      (
       [0] => 12/1 
       [1] => 48/1 
       [2] => 4621/100 
      ) 

     [GPSSpeedRef] => K 
     [GPSSpeed] => 0/1 
     [GPSDateStamp] => 2015:09:16 
    ) 

回答

0

我有一個類似的問題與數組讀取圖像的['orientation']屬性;有些沒有任何。

我找到解決的辦法是做一個檢查空()如下:

if(!empty($exif['GPSLatitude'])){ 
    //run code if long/latitude was found 
}else{ 
    //give an error message if long/latitude was NOT found 
} 

這種檢查應該沒有拋出任何錯誤的工作。