Last active
August 29, 2015 13:56
-
-
Save GeHou/8910876 to your computer and use it in GitHub Desktop.
fileTree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Return path folders and files | |
* @param string $path Input path | |
* @param showFolder $path is show folder | |
* @param pattern $path glob function's pattern | |
* @return array | |
*/ | |
function fileTree($path, $showFolder = false, $pattern = '*'){ | |
$tree = array(); | |
$nodeArr = glob(realpath($path) . '/' . $pattern); | |
foreach($nodeArr as $node){ | |
if(is_dir($node)){ | |
$rec = fileTree($node); | |
$tree['folder'][] = $node; | |
if($showFolder == true && isset($rec['folder'])) { | |
$tree['folder'] = array_merge($tree['folder'], $rec['folder']); | |
} | |
$tree['file'] = array_merge($tree['file'], $rec['file']); | |
} else{ | |
$tree['file'][] = $node; | |
} | |
} | |
return $tree; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment