2015-02-05 50 views
-1

全部, 我正在修补一个简单的上传照片,将其存储在我的服务器内的&,然后返回GPS坐标。 我正在使用标准的PHP文件上传脚本和我在这里找到的GPs解决方案。它允许我上传文件,但不会返回GPS坐标。任何人都可以帮助确定问题吗? 我的完整PHP是:如何上传照片并返回GPS合作伙伴

\t \t \t \t <?php 
 
\t \t \t \t $target_dir = "uploads/"; 
 
\t \t \t \t $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
 
\t \t \t \t $uploadOk = 1; 
 
\t \t \t \t $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
 
\t \t \t \t // Check if image file is a actual image or fake image 
 
\t \t \t \t if(isset($_POST["submit"])) { 
 
\t \t \t \t \t $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
 
\t \t \t \t \t if($check !== false) { 
 
\t \t \t \t \t \t echo "File is an image - " . $check["mime"] . "."; 
 
\t \t \t \t \t \t $uploadOk = 1; 
 
\t \t \t \t \t } else { 
 
\t \t \t \t \t \t echo "File is not an image."; 
 
\t \t \t \t \t \t $uploadOk = 0; 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t \t // Check if file already exists 
 
\t \t \t \t if (file_exists($target_file)) { 
 
\t \t \t \t \t echo "Sorry, file already exists."; 
 
\t \t \t \t \t $uploadOk = 0; 
 
\t \t \t \t } 
 
\t \t \t \t // Check file size 
 
\t \t \t \t if ($_FILES["fileToUpload"]["size"] > 5000000000) { 
 
\t \t \t \t \t echo "Sorry, your file is too large."; 
 
\t \t \t \t \t $uploadOk = 0; 
 
\t \t \t \t } 
 
\t \t \t \t // Allow certain file formats 
 
\t \t \t \t if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
 
\t \t \t \t && $imageFileType != "gif") { 
 
\t \t \t \t \t echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; 
 
\t \t \t \t \t $uploadOk = 0; 
 
\t \t \t \t } 
 
\t \t \t \t // Check if $uploadOk is set to 0 by an error 
 
\t \t \t \t if ($uploadOk == 0) { 
 
\t \t \t \t \t echo "Sorry, your file was not uploaded."; 
 
\t \t \t \t // if everything is ok, try to upload file 
 
\t \t \t \t } else { 
 
\t \t \t \t \t if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
 
\t \t \t \t \t \t echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
 
\t \t \t \t \t } else { 
 
\t \t \t \t \t \t echo "Sorry, there was an error uploading your file."; 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 

 
\t \t \t \t read_gps_location($target_file); 
 

 
\t \t \t \t /** 
 
\t \t \t \t * Returns an array of latitude and longitude from the Image file 
 
\t \t \t \t * @param image $file 
 
\t \t \t \t * @return multitype:number |boolean 
 
\t \t \t \t */ 
 
\t \t \t \t function read_gps_location(){ 
 
\t \t \t \t \t if (is_file($target_file)) { 
 
\t \t \t \t \t \t $info = exif_read_data($target_file); 
 
\t \t \t \t \t \t if (isset($info['GPSLatitude']) && isset($info['GPSLongitude']) && 
 
\t \t \t \t \t \t \t isset($info['GPSLatitudeRef']) && isset($info['GPSLongitudeRef']) && 
 
\t \t \t \t \t \t \t in_array($info['GPSLatitudeRef'], array('E','W','N','S')) && in_array($info['GPSLongitudeRef'], array('E','W','N','S'))) { 
 

 
\t \t \t \t \t \t \t $GPSLatitudeRef = strtolower(trim($info['GPSLatitudeRef'])); 
 
\t \t \t \t \t \t \t $GPSLongitudeRef = strtolower(trim($info['GPSLongitudeRef'])); 
 

 
\t \t \t \t \t \t \t $lat_degrees_a = explode('/',$info['GPSLatitude'][0]); 
 
\t \t \t \t \t \t \t $lat_minutes_a = explode('/',$info['GPSLatitude'][1]); 
 
\t \t \t \t \t \t \t $lat_seconds_a = explode('/',$info['GPSLatitude'][2]); 
 
\t \t \t \t \t \t \t $lng_degrees_a = explode('/',$info['GPSLongitude'][0]); 
 
\t \t \t \t \t \t \t $lng_minutes_a = explode('/',$info['GPSLongitude'][1]); 
 
\t \t \t \t \t \t \t $lng_seconds_a = explode('/',$info['GPSLongitude'][2]); 
 

 
\t \t \t \t \t \t \t $lat_degrees = $lat_degrees_a[0]/$lat_degrees_a[1]; 
 
\t \t \t \t \t \t \t $lat_minutes = $lat_minutes_a[0]/$lat_minutes_a[1]; 
 
\t \t \t \t \t \t \t $lat_seconds = $lat_seconds_a[0]/$lat_seconds_a[1]; 
 
\t \t \t \t \t \t \t $lng_degrees = $lng_degrees_a[0]/$lng_degrees_a[1]; 
 
\t \t \t \t \t \t \t $lng_minutes = $lng_minutes_a[0]/$lng_minutes_a[1]; 
 
\t \t \t \t \t \t \t $lng_seconds = $lng_seconds_a[0]/$lng_seconds_a[1]; 
 

 
\t \t \t \t \t \t \t $lat = (float) $lat_degrees+((($lat_minutes*60)+($lat_seconds))/3600); 
 
\t \t \t \t \t \t \t $lng = (float) $lng_degrees+((($lng_minutes*60)+($lng_seconds))/3600); 
 

 
\t \t \t \t \t \t \t //If the latitude is South, make it negative. 
 
\t \t \t \t \t \t \t //If the longitude is west, make it negative 
 
\t \t \t \t \t \t \t $GPSLatitudeRef == 's' ? $lat *= -1 : ''; 
 
\t \t \t \t \t \t \t $GPSLongitudeRef == 'w' ? $lng *= -1 : ''; 
 

 
\t \t \t \t \t \t \t return array(
 
\t \t \t \t \t \t \t \t 'lat' => $lat, 
 
\t \t \t \t \t \t \t \t 'lng' => $lng 
 
\t \t \t \t \t \t \t); 
 
\t \t \t \t \t \t }   
 
\t \t \t \t \t } 
 
\t \t \t \t \t return false; 
 
\t \t \t \t } 
 

 

 
\t \t \t \t ?>

+0

什么是错误? – 2015-02-05 16:45:51

+0

没有显示错误只是返回文件上传和文件类型的语句。谢谢 – Brad 2015-02-05 16:58:59

回答

0

你调用函数read_gps_location($ TARGET_FILE);但你不打印输出

尝试改变这一行

read_gps_location($target_file); 

print_r(read_gps_location($target_file)); 

要查看输出。它应该是数组或者是假的。

+0

完全打破了上传过程,所以我根本没有返回结果,文件也没有上传。 – Brad 2015-02-05 16:57:05