Initial commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* simpan_laporan.php — Simpan Laporan Masyarakat
|
||||
* POST: name, text, img (base64, opsional)
|
||||
*/
|
||||
require_once 'koneksi.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
echo json_encode(['success'=>false,'message'=>'Hanya POST']); exit;
|
||||
}
|
||||
|
||||
$name = $conn->real_escape_string(strip_tags($_POST['name'] ?? 'Anonim'));
|
||||
$text = $conn->real_escape_string(strip_tags($_POST['text'] ?? ''));
|
||||
$img = $_POST['img'] ?? '';
|
||||
|
||||
if (empty($text)) {
|
||||
echo json_encode(['success'=>false,'message'=>'Deskripsi kosong']); exit;
|
||||
}
|
||||
|
||||
// Validasi ukuran base64 img (max ~5MB raw → ~6.7MB base64)
|
||||
if (strlen($img) > 7_000_000) {
|
||||
echo json_encode(['success'=>false,'message'=>'Ukuran foto terlalu besar (max 5MB)']); exit;
|
||||
}
|
||||
|
||||
$imgEsc = $conn->real_escape_string($img);
|
||||
|
||||
$sql = "INSERT INTO laporan (pelapor, deskripsi, foto_base64) VALUES ('$name', '$text', '$imgEsc')";
|
||||
if ($conn->query($sql)) {
|
||||
echo json_encode(['success'=>true,'id'=>$conn->insert_id]);
|
||||
} else {
|
||||
echo json_encode(['success'=>false,'message'=>$conn->error]);
|
||||
}
|
||||
$conn->close();
|
||||
Reference in New Issue
Block a user