-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestclass.php
90 lines (80 loc) · 2.32 KB
/
Testclass.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
<?php
include('config.php');
/*
Class name : Testclass
*/
class Testclass {
public function __construct()
{
}
/**
* @param mixed $files
*
* Insert into database
* @return
*/
public function Uploadfiles($files){
$db = new Config();
//$yaml = file_get_contents('test.yaml');
//remove previous data from system
$db->truncateData();
$yml = fopen($files['name'],'r');
$path = '';
$pathsize = 0;
$front0 = '';
$front1 = '';
$front2 = '';
while ($line = fgets($yml)) {
if(strpos($line, '.') !== false){
$filepath = $path.'**'.$line;
//store path in DB
$dat = $db->insertPath($filepath,str_replace(' ', '', $line));
$fileid = $db->insertTree($front12id,$line,'file');
continue;
} else {
$pathsize = strlen($line) - strlen(ltrim($line));
if($pathsize == 0){
$front0 = $line;
$name = $line;
$front0_id = $db->insertTree(null,$line,'folder'); //get parent id
}else if($pathsize == 2){
$front2 = '';
$front1 = $line;
$name = $front1;
$front1_id = $db->insertTree($front0_id,$line,'folder');
}else if($pathsize > 2){
$front2 = $line;
$name = $front2;
$front12id = $db->insertTree($front1_id,$line,'folder');
} else {
$name = $line;
}
$path = $front0.'**'.$front1.'**'.$front2;
//store path in DB
$dat = $db->insertPath($path,str_replace(' ', '', $name));
}
}
header('Location: '.'index.php');
}
/**
* @param $search
*
* @return array
*/
public function searchText($search){
$db = new Config();
$data = $db->selectData($search);
return $data;
}
/**
* @param mixed $search
*
* @return array
*/
public function searchTree($search){
$db = new Config();
$res = $db->getTreeRecord($search);
return $res;
}
}
?>