I found this function below here on stackoverflow however, I am trying to avoid scanning any directory with the name includes.
$dir = $_SESSION['site'];
function getDirContents($dir, &$results = array()){
$files = scandir($dir);
foreach ($files as $key => $value) {
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if (!is_dir($path)) {
$results[] = $path;
} else if (is_dir($path) && $value != "." && $value != ".." ) {
getDirContents($path, $results);
$results[] = $path;
}
}
return $results;
}
I have tried adding an additional &&
as follows:
} else if (is_dir($path) && $value != "." && $value != ".." && !strstr($path,"includes/")) {
However, this does not seem to be doing the trick.
Just remove trailing slash: