As shown below:
/**
* Recursive fetch all files within a folder
* file system that returns a tree structure
* @param string $dir
* @param array $filter
* @return Array $fil Es
/function Scan_dir ($dir, $filter = Array ()) {
if (!is_dir ($dir)) return false;
$files = Array_diff (Scandir ($dir), Array ('. ', ' ... '));
if (Is_array ($files)) {
foreach ($files as $key => $value) {
if (is_dir) ($dir. '/' . $value)) {
$files [$value] = Scan_dir ($dir. '/' . $value, $filter);
Unset ($files [$key]);
Continue;
}
$pathinfo = PathInfo ($dir. '/' . $value);
$extension = array_key_exists (' extension ', $pathinfo)? $pathinfo [' extension ']: ';
if (!empty ($filter) &&!in_array ($extension, $filter)) {
unset ($files [$key]);
}
}
Unset ($key, $value);
return $files;
}
The above is a small series for everyone to bring the PHP recursive access to all the files in the directory of all the content, I hope that we support cloud Habitat Community ~