readhd.php
3.83 KB
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
<?php
#Ugly code by Anders Axesson.
# Adapted to OWL global config file by B0zz
function GetFromHD($GetWhat, $ThePath) {
if ($Dir = opendir($ThePath)) {
$FileCount = 0;
$DirCount = 0;
while($file = readdir($Dir)) {
$PathFile = $ThePath . "/" . $file; //must test with full path (is_file etc)
if(($file <> ".") and ($file <> "..")) {
if (!is_file($PathFile)) { //check if it is a folder (dir) or file (dont check if it is a link)
$DirCount++;
$Dirs[$DirCount] = $file;
}else{
$FileCount++;
$Files[$FileCount] = $file;
}
}
}
if ($GetWhat == 'file') {
$FileCount++;
$Files[$FileCount] = "[END]"; //stop looping @ this
return $Files;
}
if ($GetWhat == 'folder') {
$DirCount++;
$Dirs[$DirCount] = "[END]"; //stop looping @ this
return $Dirs;
}
}
}
function GetFileInfo($PathFile) {
$TheFileSize = filesize($PathFile); //get filesize
$TheFileTime = date("Y-m-d H:i:s", filemtime($PathFile)); //get and fix time of last modifikation
$TheFileTime2 = date("M d, Y \a\\t h:i a", filemtime($PathFile)); //get and fix time of last modifikation
$FileInfo[1] = $TheFileSize;
$FileInfo[2] = $TheFileTime; //s$modified
$FileInfo[3] = $TheFileTime2; //modified
return $FileInfo;
}
function CompareDBnHD($GetWhat, $ThePath, $DBList, $parent, $DBTable) { //compare files or folders in database with files on harddrive
$F = GetFromHD($GetWhat, $ThePath);
$RefreshPage = false; //if filez/Folderz are found the page need to be refreshed in order to see them.
if(is_array($F)) {
for($HDLoopCount = 1; $F[$HDLoopCount] !== "[END]";$HDLoopCount++) {
for($DBLoopCount = 1; $DBList[$DBLoopCount] !== "[END]";$DBLoopCount++) {
if($F[$HDLoopCount] == $DBList[$DBLoopCount]) {
unset($F[$HDLoopCount]); //removing file/folder that is in db from list of filez on disc (leaving list of filez on disc but not in db)
break;
}
}
}
for($HDLoopCount = 1; $F[$HDLoopCount] !== "[END]";$HDLoopCount++) {
if(ord($F[$HDLoopCount]) !== 0) { //if not the file/folder name is empty...
if($GetWhat == "file") {
$RefreshPage = true;
InsertHDFilezInDB($F[$HDLoopCount], $parent, $ThePath, $DBTable); //call function that inserts the filez-on-disc-but-not-in-db into the db.
}else{
$RefreshPage = false;
}
if($GetWhat == "folder") {
$RefreshPage = true;
InsertHDFolderzInDB($F[$HDLoopCount], $parent, $ThePath, $DBTable); //call function that inserts the folderz-on-disc-but-not-in-db into the db.
}
}
}
}
return $RefreshPage;
}
function InsertHDFolderzInDB($TheFolder, $parent, $ThePath, $DBTable) {
global $default;
$sql = new Owl_DB; //create new db connection
$SQL = "insert into $DBTable (name,parent,security,groupid,creatorid) values ('$TheFolder', '$parent', '$default->owl_def_fold_security', '$default->owl_def_fold_group_owner', '$default->owl_def_fold_owner')";
$sql->query($SQL);
}
function InsertHDFilezInDB($TheFile, $parent, $ThePath, $DBTable) {
global $default;
$sql = new Owl_DB; //create new db connection
$FileInfo = GetFileInfo($ThePath . "/" . $TheFile); //get file size etc. 2=File size, 2=File time (smodified), 3=File time 2 (modified)
if ($default->owl_def_file_title == "")
{
$title_name = $TheFile;
}
else
{
$title_name = $default->owl_def_file_title;
}
$SQL = "insert into $DBTable (name,filename,size,creatorid,parent,modified,description,metadata,security,groupid,smodified) values ('$title_name', '$TheFile', '$FileInfo[1]', '$default->owl_def_file_owner', '$parent', '$FileInfo[3]', '$TheFile', '$default->owl_def_file_meta', '$default->owl_def_file_security', '$default->owl_def_file_group_owner','$FileInfo[2]')";
$sql->query($SQL);
}
?>