ตอนนี้พยายามจะแก้ไข โค๊ด error โดยมันแสดง error
โดยถ้าอัพโหลดภาพที่มี gps ไม่แสดง error แต่ถ้าอัพภาพที่ไม่มี gps มันจะแสดง error
Notice: Undefined index: GPSLatitude in C:\xampp\htdocs\testgps\insert.php on line 67
Notice: Undefined index: GPSLatitudeRef in C:\xampp\htdocs\testgps\insert.php on line 67
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Notice: Undefined offset: 0 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 1 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 2 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined index: GPSLongitude in C:\xampp\htdocs\testgps\insert.php on line 68
Notice: Undefined index: GPSLongitudeRef in C:\xampp\htdocs\testgps\insert.php on line 68
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Notice: Undefined offset: 0 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 1 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 2 in C:\xampp\htdocs\testgps\insert.php on line 63
แต่พอนำ error_reporting( error_reporting() & ~E_NOTICE ); มาใส่ ไม่แสดงerror เหลือแต่
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
พอจะมีแนวทางแก้ไขยังไงบ้าง
ตัวอย่างโค๊ด
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>map</title>
</head>
<p align="center"><b>Thank You </b></font></p>
<?php
error_reporting( error_reporting() & ~E_NOTICE );
//----> Uploag to Folder name >> Photo
if(move_uploaded_file($_FILES["file1"]["tmp_name"],"Photo/".$_FILES["file1"]["name"]))
{
echo "<p align='center'><font color='#FFFFFF' size='+2'><b>Upload Completed</b></font></p>";
}
//----> Show Picture Data
if($_FILES["file1"]["error"]>0){
echo "Error : ".$_FILES["file1"]["error"]."<br>";
}else{
echo "<table width='/200 border='2' bordercolor='#FFFFFF' align='center'>";
echo "<tr>";
echo "<td><<b>File Name : </b>".$_FILES["file1"]["name"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Type : </b>".$_FILES["file1"]["type"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Size : </b>".($_FILES["file1"]["size"]/1024)." KB</td>";
echo "</tr>";
//echo "Stored in : ".$_FILES["file1"]["tmp_name"];
}
$filename = @$_FILES["file1"]["name"];
$path = 'Photo/'.$filename;
$area = @$_POST["Area"];
//---->Pull GPS from Photo
if(file_exists($path)){
$details = exif_read_data($path);
$sections = explode(',',$details['SectionsFound']);
if(in_array('GPS',array_flip($sections))){
}else{
die('GPS data not found');
}
}else{
die('File does not exists');
}
function format_gps_data($gpsdata,$lat_lon_ref){
$gps_info = array();
foreach($gpsdata as $gps){
list($j , $k) = explode('/', $gps);
array_push($gps_info,$j/$k);
}
$coordination = $gps_info[0] + ($gps_info[1]/60.00) + ($gps_info[2]/3600.00);
return (($lat_lon_ref == "S" || $lat_lon_ref == "W" ) ? '-'.$coordination : $coordination).' '.$lat_lon_ref;
}
$Lat = format_gps_data($details['GPSLatitude'],$details['GPSLatitudeRef']);
$Lon = format_gps_data($details['GPSLongitude'],$details['GPSLongitudeRef']);
if($path != ""){
$exif_date = exif_read_data($path);
$edate = $exif_date['DateTime'];
}
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Latitude : </b>".$edate."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Latitude : </b>".$Lat."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Longitude : </b>".$Lon."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Date/Time : </b></font></td>" ;
echo "</tr>";
?>
<table width='400' border='0' align='center'>
<tr>
<td>
<p align="center"><a href="Map.php?abc=<?=$path;?>"><img src="images/google-maps.png" width="140" height="140"></a></p>
<p align="center"><b>View on Map</b></font></p>
</td>
</tr>
</table>
<?php
require_once 'Connect.php';
$sql = "insert into $tbname set Photoname='$filename',Photopath='$path,'Area='$area',Date='$edate',Lat='$Lat',Lon='$Lon'";
mysql_query($sql)or die ('eror');
mysql_close();
?>
</body>
</html>
PHP แก้ไข Warning: Invalid argument supplied for foreach()
โดยถ้าอัพโหลดภาพที่มี gps ไม่แสดง error แต่ถ้าอัพภาพที่ไม่มี gps มันจะแสดง error
Notice: Undefined index: GPSLatitude in C:\xampp\htdocs\testgps\insert.php on line 67
Notice: Undefined index: GPSLatitudeRef in C:\xampp\htdocs\testgps\insert.php on line 67
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Notice: Undefined offset: 0 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 1 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 2 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined index: GPSLongitude in C:\xampp\htdocs\testgps\insert.php on line 68
Notice: Undefined index: GPSLongitudeRef in C:\xampp\htdocs\testgps\insert.php on line 68
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Notice: Undefined offset: 0 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 1 in C:\xampp\htdocs\testgps\insert.php on line 63
Notice: Undefined offset: 2 in C:\xampp\htdocs\testgps\insert.php on line 63
แต่พอนำ error_reporting( error_reporting() & ~E_NOTICE ); มาใส่ ไม่แสดงerror เหลือแต่
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\testgps\insert.php on line 59
พอจะมีแนวทางแก้ไขยังไงบ้าง
ตัวอย่างโค๊ด
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>map</title>
</head>
<p align="center"><b>Thank You </b></font></p>
<?php
error_reporting( error_reporting() & ~E_NOTICE );
//----> Uploag to Folder name >> Photo
if(move_uploaded_file($_FILES["file1"]["tmp_name"],"Photo/".$_FILES["file1"]["name"]))
{
echo "<p align='center'><font color='#FFFFFF' size='+2'><b>Upload Completed</b></font></p>";
}
//----> Show Picture Data
if($_FILES["file1"]["error"]>0){
echo "Error : ".$_FILES["file1"]["error"]."<br>";
}else{
echo "<table width='/200 border='2' bordercolor='#FFFFFF' align='center'>";
echo "<tr>";
echo "<td><<b>File Name : </b>".$_FILES["file1"]["name"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Type : </b>".$_FILES["file1"]["type"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>Size : </b>".($_FILES["file1"]["size"]/1024)." KB</td>";
echo "</tr>";
//echo "Stored in : ".$_FILES["file1"]["tmp_name"];
}
$filename = @$_FILES["file1"]["name"];
$path = 'Photo/'.$filename;
$area = @$_POST["Area"];
//---->Pull GPS from Photo
if(file_exists($path)){
$details = exif_read_data($path);
$sections = explode(',',$details['SectionsFound']);
if(in_array('GPS',array_flip($sections))){
}else{
die('GPS data not found');
}
}else{
die('File does not exists');
}
function format_gps_data($gpsdata,$lat_lon_ref){
$gps_info = array();
foreach($gpsdata as $gps){
list($j , $k) = explode('/', $gps);
array_push($gps_info,$j/$k);
}
$coordination = $gps_info[0] + ($gps_info[1]/60.00) + ($gps_info[2]/3600.00);
return (($lat_lon_ref == "S" || $lat_lon_ref == "W" ) ? '-'.$coordination : $coordination).' '.$lat_lon_ref;
}
$Lat = format_gps_data($details['GPSLatitude'],$details['GPSLatitudeRef']);
$Lon = format_gps_data($details['GPSLongitude'],$details['GPSLongitudeRef']);
if($path != ""){
$exif_date = exif_read_data($path);
$edate = $exif_date['DateTime'];
}
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Latitude : </b>".$edate."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Latitude : </b>".$Lat."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Longitude : </b>".$Lon."</font></td>" ;
echo "</tr>";
echo "<tr>";
echo "<td><font color='#FFFFFF'><b>Date/Time : </b></font></td>" ;
echo "</tr>";
?>
<table width='400' border='0' align='center'>
<tr>
<td>
<p align="center"><a href="Map.php?abc=<?=$path;?>"><img src="images/google-maps.png" width="140" height="140"></a></p>
<p align="center"><b>View on Map</b></font></p>
</td>
</tr>
</table>
<?php
require_once 'Connect.php';
$sql = "insert into $tbname set Photoname='$filename',Photopath='$path,'Area='$area',Date='$edate',Lat='$Lat',Lon='$Lon'";
mysql_query($sql)or die ('eror');
mysql_close();
?>
</body>
</html>