如何使用php删除包含其他目录、图像和php文件的目录
可能重复:如何使用php删除包含其他目录、图像和php文件的目录,php,Php,可能重复: 如何使用php删除包含其他目录、图像和php文件的目录 下面是我正在尝试的,但没有成功 unlink("./members/9/"); rmdir("./members/9/"); 您需要先删除要删除的目录中的所有文件/文件夹,然后才能删除它 $path = '/path/to/directory'; $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIter
如何使用php删除包含其他目录、图像和php文件的目录 下面是我正在尝试的,但没有成功
unlink("./members/9/");
rmdir("./members/9/");
您需要先删除要删除的目录中的所有文件/文件夹,然后才能删除它
$path = '/path/to/directory';
$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
for ($dir->rewind(); $dir->valid(); $dir->next()) {
if ($dir->isDir()) {
rmdir($dir->getPathname());
} else {
unlink($dir->getPathname());
}
}
rmdir($path);
这个看起来不错