-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.php
57 lines (52 loc) · 1.58 KB
/
utils.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
<?php
$dbs = array();
readDatasetFiles();
function c_log($msg) {
error_log($msg, 3, "data\debug.log");
}
function readDatasetFiles() {
Global $dbs;
$dbs = array();
$json = file_get_contents("dbs.json");
$json_content = json_decode($json, true);
$dbs_ids = $json_content["datasets"];
// c_log("dbs.json content");
// c_log(print_r($dbs_ids, true));
$datasets_dir = "datasets/";
$files = scandir($datasets_dir);
foreach ($files as $f) {
// c_log("files>>>> " . $f . "\n");
if ($f == "." || $f == "..") {
continue;
}
$json = file_get_contents($datasets_dir . $f);
$dbs_element = json_decode($json, true);
// c_log("id:::::::: " . $dbs_element["id"] . "\n");
// c_log(print_r($dbs_ids, true));
if (in_array($dbs_element["id"], $dbs_ids)) {
// c_log(print_r($dbs_element, true));
// c_log("true");
$dbs[$dbs_element["id"]] = $dbs_element;
} else {
c_log("error. unavailable dataset " . $dbs_element["id"]);
}
}
}
function deleteFilesInDir($dir) {
c_log("files delete from dir = " . $dir);
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir . "/" . $object) == "dir") {
deleteFilesInDir($dir . "/" . $object);
} else {
unlink($dir . "/" . $object);
}
}
}
reset($objects);
rmdir($dir);
}
}
?>