function delete($dir, $thumbnail, &$matches = [])
{
$dirs = glob($dir . '/*', GLOB_ONLYDIR);
foreach ($dirs as $dir) {
if (preg_match('@/thumb__' . $thumbnail . '$@', $dir) || preg_match('@/thumb__' . $thumbnail . '_auto@', $dir)) {
recursiveDelete($dir);
}
delete($dir, $thumbnail, $matches);
}
return $matches;
}