Source for file safe_glob.php
Documentation is available at safe_glob.php
* Extra GLOB constant for safe_glob()
* A safe empowered glob().
* Function glob() is prohibited on some server (probably in safe mode)
* (Message "Warning: glob() has been disabled for security reasons in
* (script) on line (line)") for security reasons as stated on:
* http://seclists.org/fulldisclosure/2005/Sep/0001.html
* safe_glob() intends to replace glob() using readdir() & fnmatch() instead.
* Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR
* Additional flags: GLOB_NODIR, GLOB_PATH, GLOB_NODOTS, GLOB_RECURSE
* (not original glob() flags)
* @author BigueNique AT yahoo DOT ca
* - 080324 Added support for additional flags: GLOB_NODIR, GLOB_PATH,
* GLOB_NODOTS, GLOB_RECURSE
if(is_dir($pattern)) $path = $pattern;
if (($dir= opendir($path))!== false) {
while(($file= readdir($dir))!== false) {
if($chars[0] != "." && !in_array($file,array('.','..'))) {
// Recurse subdirectories (GLOB_RECURSE)
$glob2 = safe_glob($path. '/'. $file. '/'. $mask, $flags);
$glob[] = ($flags&GLOB_PATH? $path. '/': '') . $file . ($flags&GLOB_MARK? '/': '');
if (((!($flags&GLOB_ONLYDIR)) || is_dir("$path/$file"))
$glob[] = ($flags&GLOB_PATH? $path. '/': '') . $file . ($flags&GLOB_MARK? '/': '');
if (!($flags&GLOB_NOSORT)) sort($glob);
|