-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirHelper.php
51 lines (49 loc) · 1.07 KB
/
dirHelper.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
<?php
/**
* Various file&directory helpers.
*/
class DirHelper
{
/**
* Secure string sent be a user for usage in a file name.
* @param string $name
* @return string
*/
public static function secureFileName($name)
{
$f = trim($name, './\\');
$f = strtr($f, array('\\'=>'_', '/'=>'__', '..'=>'_', ':'=>'_'));
return $f;
}
/**
* Secure string sent be a user for usage in as path (part of the path).
* @param string $path
* @return string
*/
public static function secureFilePath($path)
{
$f = trim($path, './\\');
$f = strtr($f, array('\\'=>'_', '..'=>'_', ':'=>'_'));
return $f;
}
/**
* Gets subdirectories names.
* @param type $path
* @param type $ignoreArray
* @return array Names of subdirs (or an empty array).
*/
public static function getSubdirectories($path, $ignoreArray = array('.', '..'))
{
$ret = array();
$d = dir($path);
while (false !== ($pv_entry = $d->read()))
{
if (!in_array($pv_entry, $ignoreArray) && is_dir(rtrim($path, '/').'/'.$pv_entry))
{
$ret[] = $pv_entry;
}
}
$d->close();
return $ret;
}
}