Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save faisal-ibrahim/630241578d446a280c8c31e3cac5cd52 to your computer and use it in GitHub Desktop.

Select an option

Save faisal-ibrahim/630241578d446a280c8c31e3cac5cd52 to your computer and use it in GitHub Desktop.
<?php
/**
* Function for recursive directory file list search as an array.
*
* @param mixed $dir Main Directory Path.
*
* @return array
*/
function listFolderFiles($dir)
{
$fileInfo = scandir($dir);
$allFileLists = [];
foreach ($fileInfo as $folder) {
if ($folder !== '.' && $folder !== '..') {
if (is_dir($dir . DIRECTORY_SEPARATOR . $folder) === true) {
$allFileLists[$folder] = listFolderFiles($dir . DIRECTORY_SEPARATOR . $folder);
} else {
$allFileLists[$folder] = $folder;
}
}
}
return $allFileLists;
}//end listFolderFiles()
$dir = listFolderFiles('your searching directory path ex:-F:\xampp\htdocs\abc');
echo '<pre>';
print_r($dir);
echo '</pre>'
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment