-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreceiver.php
More file actions
122 lines (102 loc) · 3.33 KB
/
Copy pathreceiver.php
File metadata and controls
122 lines (102 loc) · 3.33 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
// Database parameters
include 'database.php';
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Function to handle JSON data and insert into database
function handleJsonData($jsonData, $conn) {
// Decode JSON
$data = json_decode($jsonData, true);
if ($data === null) {
header("Location: display_data.php?status=error&message=Invalid%20JSON%20data");
exit();
}
// Required fields (minimum viable payload)
if (
!isset(
$data['os'],
$data['version'],
$data['cpu'],
$data['gpu'],
$data['ram'],
$data['cores'],
$data['threads'],
$data['vram']
)
) {
header("Location: display_data.php?status=error&message=Missing%20required%20data");
exit();
}
// Optional fields (NULL allowed)
$device = $data['device'] ?? null;
$owner = $data['owner'] ?? null;
$denomination = $data['denomination'] ?? null; // ← AJOUTÉ ICI
// Required fields
$os = $data['os'];
$version = $data['version'];
$cpu = $data['cpu'];
$gpu = $data['gpu'];
// Force numeric values + gestion "N/A" ou chaînes non numériques
$ram = (int)$data['ram'];
$cores = (int)$data['cores'];
$threads = (int)$data['threads'];
$vram = is_numeric($data['vram']) ? (int)$data['vram'] : null;
// SQL avec le nouveau champ denomination
$sql = "
INSERT INTO system_specs
(device, owner, denomination, os, version, cpu, cores, threads, gpu, vram, ram)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
";
if ($stmt = $conn->prepare($sql)) {
/*
* Types (11 paramètres maintenant) :
* s = string
* i = integer
*/
$stmt->bind_param(
"ssssssiissi", // ← un 's' supplémentaire pour denomination
$device,
$owner,
$denomination, // ← AJOUTÉ ICI
$os,
$version,
$cpu,
$cores,
$threads,
$gpu,
$vram,
$ram
);
if ($stmt->execute()) {
header("Location: index.php?status=success&message=Data%20saved%20successfully");
exit();
} else {
header("Location: index.php?status=error&message=Error%20saving%20data: " . $stmt->error);
exit();
}
$stmt->close();
} else {
header("Location: index.php?status=error&message=Database%20query%20failed: " . $conn->error);
exit();
}
}
// ===== INPUT HANDLING =====
$inputData = file_get_contents('php://input');
if (!empty($inputData)) {
handleJsonData($inputData, $conn);
} elseif (isset($_FILES['jsonFile']) && $_FILES['jsonFile']['error'] === UPLOAD_ERR_OK) {
if ($_FILES['jsonFile']['type'] === 'application/json') {
$fileContent = file_get_contents($_FILES['jsonFile']['tmp_name']);
handleJsonData($fileContent, $conn);
} else {
header("Location: index.php?status=error&message=Uploaded%20file%20is%20not%20a%20valid%20JSON%20file");
exit();
}
} else {
header("Location: index.php?status=error&message=No%20JSON%20data%20provided");
exit();
}
$conn->close();
?>