setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $data = Array(); //print_r($_FILES); if(isset($_FILES['my_file'])){ echo "
" . $_FILES['my_file']['name'][$i] . " | "; echo "" . count($fileContents) . " | "; $updated = 0; foreach($fileContents as $row) { $row=explode(",", $row); if(count($row)!=8) continue; try { //connect as appropriate as above $stmt = $db->prepare("REPLACE INTO markers (timestamp,lat,lng,alt,hdop,speed,voltage,rssi) VALUES (?,?,?,?,?,?,?,?)"); $stmt->execute(array($row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8])); $updated += $stmt->rowCount(); } catch(PDOException $ex) { echo "An Error occured!"; //user friendly message //some_logging_function($ex->getMessage()); } } echo "" . $updated . " rows updated | "; } elseif($ext == "nmea") { $fp = fopen($_FILES['my_file']["tmp_name"][$i], "r"); $fileContents=explode("\n", fread($fp, $_FILES['my_file']["size"][$i])); fclose($fp); echo "||
" . $_FILES['my_file']['name'][$i] . " | "; echo "" . count($fileContents) . " | "; $nmea = new NmeaParser(); foreach($fileContents as $row) { $nmea->ParseLine($row); } $data = RamerDouglasPeucker2d(array_values($nmea->DumpNmea()), 0.00001); //.0001 = 7m echo "" . count($data) . " | "; $oldLat = $oldLong = 0; $rows = 0; $updated = 0; foreach($data as $row) { if(distance($oldLat, $oldLong, $row["lat"], $row["long"]) < 0.005) continue; $oldLat = $row["lat"]; $oldLong = $row["long"]; if($row["speed"] == 0) { $row["speed"] = null; } $rows++; try { $stmt = $db->prepare("REPLACE INTO markers (timestamp,lat,lng,alt,hdop,speed) VALUES (?,?,?,?,?,?)"); $stmt->execute(array(date('Y-m-d H:i:s', $row['Unix']), $row["lat"], $row["long"], $row["alt"], intval($row["hdp"]), $row["speed"] * 100)); $updated += $stmt->rowCount(); } catch(PDOException $ex) { echo "An Error occured!"; //user friendly message error_log($ex->getMessage()); } } echo "" . $rows . " | "; echo "" . $updated . " rows updated | "; } } echo '