Для поиска файлов в PHP вы можете использовать glob
:
http://php.net/manual/en/function.glob.php
Чтобы получить список файлов для пути, вы можете использовать scandir
:
http://php.net/manual/en/function.scandir.php
Пример
$dir = "/path/to/search/in/*.txt"; //search a path for only .txt files
foreach(glob($dir) as $file)
{
//print out the files that match
echo "filename: $file : filetype: " . filetype($file) . "<br />";
}
Пользовательский рекурсивный шар
От: http://snipplr.com/view.php?codeview&id=16233
rglob($pattern, $flags = 0, $path = '')
{
if (!$path && ($dir = dirname($pattern)) != '.')
{
if ($dir == '\\' || $dir == '/') $dir = '';
return rglob(basename($pattern), $flags, $dir . '/');
}
$paths = glob($path . '*', GLOB_ONLYDIR | GLOB_NOSORT);
$files = glob($path . $pattern, $flags);
foreach ($paths as $p) $files = array_merge($files, rglob($pattern, $flags, $p . '/'));
return $files;
}