Last active
May 6, 2019 11:24
-
-
Save larchanka/ec037a7b8a299bc8860d05f3728c3b2a to your computer and use it in GitHub Desktop.
Function to scan directory and return array of files
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 | |
function dirToArray($dir) { | |
$ignoredPath = array( | |
".", | |
"..", | |
".htaccess" | |
); | |
$result = array(); | |
$cdir = scandir($dir); | |
foreach ($cdir as $key => $value) { | |
if (!in_array($value, $ignoredPath)) { | |
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { | |
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value); | |
} else { | |
$result[] = $value; | |
} | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment