Skip to content

Instantly share code, notes, and snippets.

@064023
Last active August 21, 2016 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 064023/2880c341c1267826981e5bf8e04bd53e to your computer and use it in GitHub Desktop.
Save 064023/2880c341c1267826981e5bf8e04bd53e to your computer and use it in GitHub Desktop.
simple location sender.php 使用方法:將此 php 放到伺服器,傳送資料時直接傳到這個網址,就會記錄在 data 資料夾;查看資料時,在網址後面加上 group 參數即可查看那一組的資料
<?php
mb_parse_str($_SERVER["QUERY_STRING"], $qs);
$group = array_key_exists('group', $qs) ? preg_replace('/\W/', "", $qs["group"]) : "";
if($group==""){
$postdata = $HTTP_RAW_POST_DATA;
// {"type":"Feature","properties":null,"geometry":{"type":"Point","coordinates":[120.6702662,24.1272791,0]}}
// {"type":"Feature","geometry":{"type":"Point","coordinates":[-100.5,37.35,0]},"properties":{"status":"ok","group_id":"Developer","user_id":"Charles"}}
$input = json_decode($postdata, true);
$group = preg_replace('/\W/', "", $input["properties"]["group_id"]);
$user = preg_replace('/\W/', "", $input["properties"]["user_id"]);
$folder = "data/".$group;
if(!is_dir($folder)){
mkdir($folder);
}
$file = $folder."/".$user.".json";
//$file = $folder."123.txt";
if (($fd = fopen($file, "w")) !== false) {
fwrite($fd, $postdata);
fclose($fd);
}
}else{
$folder = "data/".$group;
if($group!="" && is_dir($folder)){
$files = scandir($folder);
//var_dump($files);
$groupgeojson = array("type" => "FeatureCollection", "features" => array());
foreach($files as $f){
if($f!="." && $f!=".."){
$point = file_get_contents($folder."/".$f);
$point = json_decode($point,true);
array_push($groupgeojson["features"], array(
"type" => "Feature",
"geometry" => array(
"type" => "Point",
"coordinates" => array($point["geometry"]["coordinates"][0], $point["geometry"]["coordinates"][1])
),
"properties" => array(
"time" => date("Y/m/d H:i:s",filemtime($folder."/".$f)),
"status" => $point["properties"]["status"],
"group_id" => $point["properties"]["group_id"],
"user_id" => $point["properties"]["user_id"],
"name" => $point["properties"]["user_id"]
)
));
}
}
echo json_encode($groupgeojson);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment