Last active
December 17, 2015 04:28
-
-
Save 321zeno/5550584 to your computer and use it in GitHub Desktop.
A recursive PHP function that returns all the contents of a folder
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
function explore_recursive($path) { | |
$contents = glob($path .'*', GLOB_BRACE); | |
if (count($contents) > 0) { | |
foreach ($contents as $item) { | |
$file['name'] = basename($item); | |
// $file['location'] = $item; | |
$found = explore_recursive($item . '/'); | |
if ($found) { $file['contents'] = $found; } | |
$branch[] = $file; | |
} | |
return $branch; | |
} | |
return false; | |
} | |
//you can use it like | |
$nodes = explore_recursive('../my folder/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment