我跟着this SO thread遞歸刪除目錄(請參閱下面的代碼)。問題是我壓縮了目錄的內容並下載了壓縮文件後無法獲取這些命令來完成它們的工作。在壓縮並下載其內容後遞歸地刪除目錄失敗
文件/文件夾權限似乎不是問題,因爲正如我所說的代碼工作得很好,如果沒有涉及到文件夾壓縮。
任何人有任何想法?
$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);
看來,PHP和你的服務器目錄捆綁在一起,拉鍊後它說嘿我沒有完成,這些目錄/文件不是免費的...(不知道罪魁禍首),但是當你做一個副本說到臨時目錄,壓縮文件夾和文件,然後刪除原來的目錄?只是好奇。 –
嗨@FrankTudor謝謝,我每次都在創建一個新的目錄。 –
只是好奇...你在Windows或Linux? –