-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_data.php
More file actions
55 lines (50 loc) · 1.4 KB
/
Copy pathimport_data.php
File metadata and controls
55 lines (50 loc) · 1.4 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
<?php
/**
* NFC/RFID Report Generator
* Import Data Script
*
* Tento skript zpracovává nahraný JSON soubor a vrací data pro formulář
*/
// Kontrola, zda byl soubor nahrán
if (!isset($_FILES['dataFile']) || $_FILES['dataFile']['error'] !== UPLOAD_ERR_OK) {
$response = [
'success' => false,
'message' => 'Chyba při nahrávání souboru.'
];
header('Content-Type: application/json');
echo json_encode($response);
exit;
}
// Kontrola typu souboru
$fileInfo = pathinfo($_FILES['dataFile']['name']);
if ($fileInfo['extension'] !== 'json') {
$response = [
'success' => false,
'message' => 'Neplatný formát souboru. Nahrajte soubor JSON.'
];
header('Content-Type: application/json');
echo json_encode($response);
exit;
}
// Načtení obsahu souboru
$fileContent = file_get_contents($_FILES['dataFile']['tmp_name']);
$reportData = json_decode($fileContent, true);
// Kontrola, zda se podařilo dekódovat JSON
if ($reportData === null) {
$response = [
'success' => false,
'message' => 'Neplatný formát JSON souboru.'
];
header('Content-Type: application/json');
echo json_encode($response);
exit;
}
// Vrácení dat
$response = [
'success' => true,
'message' => 'Data byla úspěšně načtena.',
'data' => $reportData
];
header('Content-Type: application/json');
echo json_encode($response);
exit;