readhd.php
7.22 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
/**
* ReadHD.php
*
* this is used for file system manipulation
*
* Copyright (c) 1999-2002 The Owl Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
* @version v 1.1.1.1 2002/12/04
* @author michael
* @package Owl
*/
#Ugly code by Anders Axesson.
# Adapted to OWL global config file by B0zz
//-------------------------------------------------------------
/**
* Function GetFromHD($GetWhat, $ThePath)
*
* Retrieves files/folders from the Hard Drive, given
* a file/folder to get and a path
*
* @param $GetWhat
* The File/Folder(s) that needs to be retrieved
* @param $ThePath
* The Path to Search for the File/Folder(s)
* @return $Files
* Returns an array of Files that needs to be retrieved
* @return $Folders
* Returns an array Folder(s) that needs to be retrieved
*/
//-------------------------------------------------------------
// Usable
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 it is a file add it to an array of files and return it
if ($GetWhat == 'file')
{
$FileCount++;
$Files[$FileCount] = "[END]"; //stop looping @ this
return $Files;
}
// if it is a folder add it to the array of folders and return it
if ($GetWhat == 'folder')
{
$DirCount++;
$Dirs[$DirCount] = "[END]"; //stop looping @ this
return $Dirs;
}
}
}
//-------------------------------------------------------------
/**
* Function GetFileInfo($PathFile)
*
* Gets the information on the specified file i.e. modification
* and file size
*
* @param $PathFile
* The Path to the File
* @return $FileInfo
* Returns an array with the information of the file
*/
//-------------------------------------------------------------
// Usable
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
*
* @param $GetWhat
* The File/Folder(s) that will be compared
* @param $ThePath
* The Path of the File/Folder(s)
* @param $DBList
* The List of files in the DB
* @param $Parent
* The parent folder id
* @param $DBTable
* The DBTable to compare to
* @return $RefreshPage
* Return true or false if page needs to be refreshed
*/
//-------------------------------------------------------------
// Usable
function CompareDBnHD($GetWhat, $ThePath, $DBList, $parent, $DBTable) { //compare files or folders in database with files on harddrive
// get from HD the relevant Files/Folders, store in array
$F = GetFromHD($GetWhat, $ThePath);
$RefreshPage = false; //if filez/Folders are found the page need to be refreshed in order to see them.
// if array exists
if(is_array($F))
{
// loop through file/folderarray and Dblist array to compare them
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;
}
}
}
// if certain files/Folders are not in the DB but are on the list, add them to the DB
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 files-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 folders-on-disc-but-not-in-db into the db.
}
}
}
}
// return true or false
return $RefreshPage;
}
//-------------------------------------------------------------
/**
* Function InsertHDFolderzInDB($TheFolder, $parent, $ThePath, $DBTable)
*
* Compare files or folders in database with files on harddrive
*
* @param $TheFolder
* The Folder to be inserted
* @param $Parent
* The parent folder id
* @param $ThePath
* The Path of the Folder
* @param $DBTable
* The DBTable to insert into
*/
//-------------------------------------------------------------
// Usable
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)
*
* Compare files or folders in database with files on harddrive
*
* @param $TheFile
* The Folder to be inserted
* @param $Parent
* The parent folder id
* @param $ThePath
* The Path of the File
* @param $DBTable
* The DBTable to insert into
*/
//-------------------------------------------------------------
// Usable
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 there is no file title assign it to default file title
if ($default->owl_def_file_title == "")
{
$title_name = $TheFile;
}
else
{
$title_name = $default->owl_def_file_title;
}
// insert into DB
$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);
}
?>