Upload files to "/"
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
include 'connect.php';
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
if ($action === 'tampil') {
|
||||
$sql = "SELECT * FROM data_spasial ORDER BY id DESC";
|
||||
$result = $conn->query($sql);
|
||||
$data = [];
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode($data);
|
||||
}
|
||||
elseif ($action === 'simpan') {
|
||||
$nama = trim($_POST['nama'] ?? '');
|
||||
$jenis_objek = $_POST['jenis_objek'] ?? '';
|
||||
$status = $_POST['status'] ?? '';
|
||||
$ukuran = floatval($_POST['ukuran'] ?? 0);
|
||||
$geojson = $_POST['geojson'] ?? '';
|
||||
|
||||
if ($nama === '' || $jenis_objek === '' || $geojson === '') {
|
||||
echo json_encode(["status" => "error", "message" => "Nama, jenis objek, dan geometri wajib diisi."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO data_spasial (nama, jenis_objek, status, ukuran, geojson) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt->bind_param("sssds", $nama, $jenis_objek, $status, $ukuran, $geojson);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
}
|
||||
elseif ($action === 'hapus') {
|
||||
$id = intval($_POST['id'] ?? 0);
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(["status" => "error", "message" => "ID tidak valid."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("DELETE FROM data_spasial WHERE id = ?");
|
||||
$stmt->bind_param("i", $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["status" => "success"]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
}
|
||||
else {
|
||||
echo json_encode(["status" => "error", "message" => "Action tidak dikenali."]);
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
?>
|
||||
Reference in New Issue
Block a user