Get the directory contents recursively.
require 'get_dir.php';
printf('<ul>');
foreach(get_dir('/path/to/directory') as $item)
{
printf('<li>%s</li>', $item);
}
printf('</ul>');
<?php | |
/** | |
* Get the directory contents recursively. | |
* | |
* @author JoseRobinson.com | |
* @link GitHup: https://gist.github.com/5324874 | |
* @version 201304062329 | |
* @param string $dir | |
* @return array | |
*/ | |
function get_dir($dir) | |
{ | |
$files_list = array(); | |
foreach(scandir($dir) as $file) | |
{ | |
if (in_array($file, array('.', '..'))) continue; | |
$full_path = "{$dir}/{$file}"; | |
if (is_dir($full_path)) | |
{ | |
$files_list = array_merge($files_list, get_dir($full_path)); | |
} | |
else | |
{ | |
$files_list[] = realpath($full_path); | |
} | |
} | |
return $files_list; | |
} |