(一)
<?php
$base_path = "./upload/"; // 接收文件目录
$target_path = $base_path . basename ( $_FILES ['uploadfile'] ['name'] );
if (move_uploaded_file ( $_FILES ['uploadfile'] ['tmp_name'], $target_path )) {
$array = array (
"code" => "1",
"message" => $_FILES ['uploadfile'] ['name']
);
echo json_encode ( $array );
} else {
$array = array (
"code" => "0",
"message" => "There was an error uploading the file, please try again!" . $_FILES ['uploadfile'] ['error']
);
echo json_encode ( $array );
}
?>
(二)
<?php
// array for JSON response
//此处需要将数据库名和表明还有密码做相应修改,改成你自己的
$con = mysql_connect("localhost","root",null);
if (!$con) {
die('Could not connect:'.mysql_error() );
}
mysql_select_db("a0722152915", $con);
$response = array();
include("conn.php");
// check for required fields
if (isset($_POST['time']) && isset($_POST['lat']) &&
isset($_POST['lon'])&& isset($_POST['encyptiontype'])&&
isset($_POST['rssi'])&& isset($_POST['name'])) {
$time = $_POST['time'];
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$encyptiontype = $_POST['encyptiontype'];
$rssi = $_POST['rssi'];
$name = $_POST['name'];
$result = mysql_query("INSERT INTO wifi_state(time, lat,
lon,encyptiontype,rssi,name) VALUES('$time', '$lat',
'$lon','$encyptiontype','$rssi','$name')");
echo $result;
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>