-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploadFiles.php
140 lines (131 loc) · 4.26 KB
/
uploadFiles.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
if (!file_exists('files')) {
mkdir('files', 0777);
}
if (!file_exists('files/txt')) {
mkdir('files/txt', 0777);
}
if (!file_exists('files/gpx')) {
mkdir('files/gpx', 0777);
}
if (!file_exists('files/csv')) {
mkdir('files/csv', 0777);
}
if (!file_exists('blackbox-tools/logs')) {
mkdir('blackbox-tools/logs', 0777);
}
set_time_limit(180); //set php timeout at 3min
$filename = $_FILES['file']['name'];
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if ($ext == 'gpx')
{
if(move_uploaded_file($_FILES['file']['tmp_name'], 'files/gpx/'.$_FILES['file']['name']))
{
echo "1";
}
else
{
echo "0";
}
/*echo "File uploaded successfully.";*/
}
elseif($ext == 'txt')
{
if(move_uploaded_file($_FILES['file']['tmp_name'], 'blackbox-tools/logs/'.$_FILES['file']['name']))
{
//shell_exec("blackbox-tools/./blackbox_decode blackbox-tools/logs/".$_FILES['file']['name']." 2>&1"); //LINUX
shell_exec("blackbox-tools\blackbox_decode.exe blackbox-tools\logs\\".$_FILES['file']['name']." 2>&1"); //WINDOWS
rename("blackbox-tools/logs/".pathinfo($filename, PATHINFO_FILENAME).".01.gps.csv","files/csv/".pathinfo($filename, PATHINFO_FILENAME).".01.gps.csv");
rename("blackbox-tools/logs/".pathinfo($filename, PATHINFO_FILENAME).".01.csv","files/csv/".pathinfo($filename, PATHINFO_FILENAME).".01.csv");
rename("blackbox-tools/logs/".pathinfo($filename, PATHINFO_FILENAME).".01.gps.gpx","files/gpx/".pathinfo($filename, PATHINFO_FILENAME).".01.gps.gpx");
unlink("blackbox-tools/logs/".pathinfo($filename, PATHINFO_FILENAME).".01.event");
//trim the .txt file
$handle = fopen('blackbox-tools/logs/' . $_FILES['file']['name'], "r");
$linenum = 0;
$out = '';
if ($handle) {
while ((($line = fgets($handle)) !== false)&&(strpos($out.$line,0xbb)==NULL)){ //stops reading when binary appears with »
$out = $out.$line;
$linenum=$linenum+1;
}
fclose($handle);
}
$myfile = fopen('files/txt/' . pathinfo($filename, PATHINFO_FILENAME) . '.01.txt', "w") or die("Unable to open file!");
fwrite($myfile, $out);
fclose($myfile);
//decimate the .gps.csv file
$handle = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.gps.csv", "r")or die("Unable to open file!");
$linenum = 0;
$out = '';
$linecount = 0;
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
$handle = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.gps.csv", "r")or die("Unable to open file!");
if ($handle) {
$out = fgets($handle); //skip title bar
if (($line = fgets($handle)) !== false) //get the first line
{
$out = $line;
$temp = explode(",", $line);
$time0 = intval(substr($temp[0], 0, -6));//downsize to 1Hz
while (($line = fgets($handle)) !== false)
{
$temp = explode(",", $line);
$time1 = intval(substr($temp[0], 0, -6));//downsize to 1Hz
if($time1 > $time0)
{
$time0 = $time1;
$out = $out.$line;
}
}
}
}
fclose($handle);
$myfile = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.gps.csv", "w") or die("Unable to open file!");
fwrite($myfile, $out);
fclose($myfile);
//decimate the .csv file
$handle = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.csv", "r")or die("Unable to open file!");
$linenum = 0;
$out = '';
$linecount = 0;
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
$handle = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.csv", "r")or die("Unable to open file!");
if ($handle) {
//$out = fgets($handle); //skip title bar
if (($line = fgets($handle)) !== false) //get the first line
{
$out = $line;
$temp = explode(",", $line);
$time0 = intval(substr($temp[1], 0, -6));//downsize to 1Hz
while (($line = fgets($handle)) !== false)
{
$temp = explode(",", $line);
$time1 = intval(substr($temp[1], 0, -6));//downsize to 1Hz
if($time1 > $time0)
{
$time0 = $time1;
$out = $out.$line;
}
}
}
}
fclose($handle);
$myfile = fopen('files/csv/' . pathinfo($filename, PATHINFO_FILENAME) . ".01.csv", "w") or die("Unable to open file!");
fwrite($myfile, $out);
fclose($myfile);
echo "1";
}
else
{
echo "0";
}
}
?>