Initial Commit: Tugas Semua Pertemuan
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$deskripsi = mysqli_real_escape_string($conn, $_POST['deskripsi']);
|
||||
$lat = floatval($_POST['lat']);
|
||||
$lng = floatval($_POST['lng']);
|
||||
|
||||
// Upload foto
|
||||
$targetDir = "uploads/";
|
||||
if (!file_exists($targetDir)) {
|
||||
mkdir($targetDir, 0777, true);
|
||||
}
|
||||
$fileName = time() . '_' . basename($_FILES["foto"]["name"]);
|
||||
$targetFilePath = $targetDir . $fileName;
|
||||
$fileType = strtolower(pathinfo($targetFilePath, PATHINFO_EXTENSION));
|
||||
$allowedTypes = array('jpg', 'jpeg', 'png', 'gif');
|
||||
|
||||
if (in_array($fileType, $allowedTypes)) {
|
||||
if (move_uploaded_file($_FILES["foto"]["tmp_name"], $targetFilePath)) {
|
||||
$query = "INSERT INTO jalan_rusak (deskripsi, foto, latitude, longitude) VALUES ('$deskripsi', '$fileName', $lat, $lng)";
|
||||
if (mysqli_query($conn, $query)) {
|
||||
echo "success";
|
||||
} else {
|
||||
echo "db_error: " . mysqli_error($conn);
|
||||
}
|
||||
} else {
|
||||
echo "upload_failed";
|
||||
}
|
||||
} else {
|
||||
echo "invalid_format";
|
||||
}
|
||||
} else {
|
||||
echo "invalid_request";
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user