-
Notifications
You must be signed in to change notification settings - Fork 0
/
savedata.php
40 lines (33 loc) · 1.29 KB
/
savedata.php
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
header('X-Content-Type-Options: nosniff');
$userAnswers = array();
$countArray = array();
$count="undefined";
if(isset($_POST['currentUser'])){
$countArray = $_POST['currentUser'];
for ($x = 0; $x < sizeof($countArray); $x++) {
$count = $countArray[$x];
}
}
if (isset($_POST['userAnswers'])) {
$userAnswers = $_POST['userAnswers'];
$stringToSave = "id\thh:mm:ss\tY/N\tRating\tFacit\tText\tTextB\tTextC\n";
for ($x = 0; $x < sizeof($userAnswers); $x++) {
$stringToSave = $stringToSave . $userAnswers[$x] . "\n";
}
$time = date("Y_m_d_H_i_sa"); //save date
$filename = "C:/xampp/htdocs/d3-hierarchy/collectData/"."testPerson_". $count. "_Time_" . $time . ".txt";
$dataFile = fopen($filename, "w"); // Use "w" mode for creating a new file or overwriting an existing file
if ($dataFile) {
if (fwrite($dataFile, $stringToSave) !== false) {
fclose($dataFile);
//fclose($countParticipant);
echo "Data has been successfully saved to the file.";
} else {
echo "Error writing data to file.";
}
} else {
echo "Error opening file for writing.";
}
}
?>