There is a main directory for example
$dir = $_SERVER['DOCUMENT_ROOT'].'/contents/'; It contains files and subdirectories that also contain files and may also contain subdirectories. I am trying to get a recursively common array from all files:
function allFiles($dir) { $files = []; foreach(glob($dir.'*') as $fileOrDir) { if(is_dir($fileOrDir)) { $files = array_merge($files, allFiles($fileOrDir)); } else { $files[] = $fileOrDir; } } return $files; } But I get an error 500 Internal Server Error .
I saw the answers to the question by reference Get a list of files in the directory and subdirectories, but I would like to understand what the problem is with my more simplified version