-1

总而言之,我正在修改一个简单的表单来上传照片,将其存储在我的服务器中,然后返回 GPS 坐标。我正在使用标准的 PHP 文件上传脚本和我在这里找到的 GPs 解决方案。它允许我上传文件但不返回 GPS 坐标。任何人都可以帮助确定问题吗?我完整的php是:

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

				read_gps_location($target_file);

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

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

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

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

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

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

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


				?> 

4

1 回答 1

0

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

尝试更改此行

read_gps_location($target_file);

print_r(read_gps_location($target_file)); 

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

于 2015-02-05T16:47:44.443 回答