-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrecord_backend.php
More file actions
42 lines (34 loc) · 1.1 KB
/
Copy pathrecord_backend.php
File metadata and controls
42 lines (34 loc) · 1.1 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
<?php
define('CURSCRIPT', 'record_backend');
require './include/common.inc.php';
try {
$jsonData = file_get_contents('php://input');
$requestData = json_decode($jsonData, true);
if ($requestData === null) {
http_response_code(400);
$response = ["message" => "Invalid JSON data"];
echo json_encode($response);
return;
}
global $gamenum;
$lastRecord = $requestData['lastRecord'];
$nickinfo = $requestData['nickinfo'];
$directoryPath = "./records/$gamenum/$nickinfo";
$filePath = "$directoryPath/record.txt";
// 创建目录
if (!is_dir($directoryPath) && !mkdir($directoryPath, 0777, true)) {
throw new Exception('Failed to create directory');
}
// 写入数据到文件
if (!file_put_contents($filePath, $lastRecord . "\n", FILE_APPEND)) {
throw new Exception('Failed to write data to file');
}
// 返回信息
echo json_encode([
"message" => "Success",
]);
} catch (Exception $e) {
http_response_code(500);
$response = ["message" => $e->getMessage()];
echo json_encode($response);
}