Perbaiki .gitignore agar log dan file sensitif tidak ikut commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
header("Content-Type: application/json");
|
||||
|
||||
// direktori upload
|
||||
$uploadDir = __DIR__ . "/../img/pesan/";
|
||||
if (!file_exists($uploadDir)) {
|
||||
mkdir($uploadDir, 0777, true);
|
||||
}
|
||||
|
||||
if (!isset($_FILES['file'])) {
|
||||
echo json_encode(["status" => "error", "message" => "No file uploaded"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$file = $_FILES['file'];
|
||||
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
||||
$allowed = ['jpg', 'jpeg', 'png', 'gif'];
|
||||
|
||||
if (!in_array($ext, $allowed)) {
|
||||
echo json_encode(["status" => "error", "message" => "Invalid file type"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$newName = uniqid("img_") . "." . $ext;
|
||||
$target = $uploadDir . $newName;
|
||||
|
||||
if (move_uploaded_file($file['tmp_name'], $target)) {
|
||||
$url = "https://manjapro.net/img/pesan/" . $newName;
|
||||
echo json_encode(["status" => "success", "url" => $url]);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "Failed to move file"]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user