-
Notifications
You must be signed in to change notification settings - Fork 0
/
getLicense.php
58 lines (46 loc) · 1.35 KB
/
getLicense.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
<?php // /Volumes/USB DISK/
header('Content-type: application/json');
$dir = '/media/pi/';
if (file_exists($dir.'LICENSE/')) {
$licenseFile = 'license.txt';
if (file_exists($dir.'LICENSE/'.$licenseFile)) {
$license = file_get_contents($dir.'LICENSE/'.$licenseFile);
$json = array(
'license' => $license
);
} else {
$json = array(
'license' => '404'
);
}
} else {
$filesDir = scandir($dir);
if ($filesDir[2]) {
$allFiles = scandir($dir.$filesDir[2]);
$json = array(
'license' => 'files',
'files' => array()
);
$i = 0;
$pag = 0;
foreach ($allFiles as $file) {
if (substr($file, 0, 1) !== '.') {
$extension = pathinfo($dir.$filesDir[2] . $file, PATHINFO_EXTENSION);
if ($extension === 'txt' || $extension === 'jpg' || $extension === 'jpeg' || $extension === 'png') {
$json['files'][$pag][$i] = $file;
if ($i % 9 === 0 && $i > 0) {
$pag++;
$i = 0;
} else {
$i++;
}
}
}
}
} else {
$json = array(
'license' => '404'
);
}
}
echo json_encode($json);