-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-functions.php
69 lines (67 loc) · 2.71 KB
/
file-functions.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
<?php
function _file_readdir($path,$exclude = ".|..")
{
$exclude_array = explode("|", $exclude);
if ($handle = opendir($path)):
while (false !== ($file = readdir($handle))):
if(!in_array(strtolower($file), $exclude_array)):
if (is_dir($path.'/'.$file)):
$output['dir'][] = $file;
elseif(is_file($path.'/'.$file)):
$output['file'][] = $file;
endif;
endif;
endwhile;
closedir($handle);
endif;
return($output);
}
function _file_get_dir_files($path,$filetype = 'csv',$fullpath = false) {
if ($handle = opendir($path)):
/* This is the correct way to loop over the directory. */
$files = false;
while (false !== ($entry = readdir($handle))):
//echo "$entry\n";
if ( $entry !='.' && $entry !='..' && substr($entry, -3) == $filetype):
if (!is_dir($path.'/'.$entry)):
if ($fullpath == true):
$files[] = $path . '/' . $entry;
else:
$files[] = $entry;
endif;
endif;
endif;
endwhile;
closedir($handle);
endif;
return($files);
}
function _file_open_delimited($file,$delim){
$row = 0;
if(($handle = fopen($file, "r")) !== FALSE):
while (($data = fgetcsv($handle, 1000,$delim)) !== FALSE):
$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++):
// echo $data[$c] . "<br />\n";
endfor;
$output['filename'] = $file;
$output[$row]['date'] = trim($data[0]);
$output[$row]['location'] = trim($data[1]);
$output[$row]['accuracy'] = trim($data[2]);
$output[$row]['altitude'] = trim($data[3]);
$output[$row]['speed'] = trim($data[4]);
$output[$row]['cellid'] = trim($data[5]);
$output[$row]['cellsig'] = trim($data[6]);
$output[$row]['cellsvr'] = trim($data[7]);
if (isset($data[8])):
$output[$row]['battery'] = trim($data[8]);
endif;
if (isset($data[9])):
$output[$row]['power'] = trim($data[9]);
endif;
endwhile;
endif;
return($output);
}