How do I do this in php: retrieve the number of subfolders and their names inside a specified folder, as well as retrieve the number of files as well as their names in that subfolder. I'm making an image gallery for my brother.
Like this? function dir_get_contents($dir) { $dir = rtrim($dir, '/\\'); if (!$handle = @opendir($dir)) { trigger_error("Unable to open directory {$dir}"); return false; } $files = array(); while (($entry = readdir($handle)) !== false) { if (!in_array($entry, array('.', '..'))) { $path = "{$dir}/{$entry}"; if (is_file($path)) { $files[] = $path; } else if (is_dir($path) AND $tmp = dir_get_contents($path)) { $files = array_merge($files, $tmp); } } } closedir($handle); return $files; } PHP: Usage example: $files = dir_get_contents('path/to/dir'); echo '<pre>' . print_r($files, true) . '</pre>'; PHP: