Find all files and folders in the specified directory.
function getDirRecursive($dir, &$output = []) { $scandir = scandir($dir); foreach ($scandir as $a => $name) { $path = realpath($dir . DIRECTORY_SEPARATOR . $name); if (!is_dir($path)) { $output[] = $path; } else if ($name != "." && $name != "..") { getDirRecursive($path, $output); $output[] = $path; } } return $output; } var_dump(getDirRecursive('/home/user/stuff'));
Output (example):
array (size=4) 0 => string '/home/user/stuff/folder1/image1.jpg' (length=35) 1 => string '/home/user/stuff/folder1/image2.jpg' (length=35) 2 => string '/home/user/stuff/folder2/subfolder1/image1.jpg' (length=46) 3 => string '/home/user/stuff/image1.jpg' (length=27)
Hors Sujet Nov 05 '15 at 16:50 2015-11-05 16:50
source share