function treeDirectory($dir)
{
$files = array();
$dirpath = realpath($dir);
$filenames = scandir($dir);
foreach ($filenames as $filename)
{
if ($filename=='.' || $filename=='..')
{
continue;
}
$file = $dirpath . DIRECTORY_SEPARATOR . $filename;
if (is_dir($file))
{
$files = array_merge($files, self::treeDirectory($file));
}
else
{
$files[] = $file;
}
}
return $files;
}