我按照这个 SO 线程递归地删除了一个目录(见下面的代码)。问题是在压缩目录内容并下载 zip 文件后,我无法让这些命令执行它们的操作。
文件/文件夹权限似乎不是问题,因为正如我所说,如果不涉及文件夹压缩,代码就可以正常工作。
有人有想法么?
$this->zip->download($file_name); //a Codeigniter function, though think it could be any function that executes the zip file download.
$dir='uploads/folder1';
//the contents of folder1 are "foo1.png" and "foo2.png"
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $fileinfo) {
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
$todo($fileinfo->getRealPath());
}
rmdir($dir);