- RecursiveIteratorIteratorを使うと楽。
<?php
$dir = '/path/to/dir';
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ( $files as $file )
{
if ( $file->isDir() === true )
{
rmdir($file->getPathname());
}
else
{
unlink($file->getPathname());
}
}
rmdir($dir);