Skip to content

Instantly share code, notes, and snippets.

@321zeno
Last active December 17, 2015 04:28
Show Gist options
  • Save 321zeno/5550584 to your computer and use it in GitHub Desktop.
Save 321zeno/5550584 to your computer and use it in GitHub Desktop.
A recursive PHP function that returns all the contents of a folder
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