下面是我使用遞歸刪除文件夾和文件PHP遞歸刪除文件夾
function rmdir_recursively($dir) {
if (!is_dir($dir) || is_link($dir)) return unlink($dir);
foreach (scandir($dir) as $file) {
if ($file == '.' || $file == '..') continue;
if (!rmdir_recursively($dir . DIRECTORY_SEPARATOR . $file)) {
chmod($dir . DIRECTORY_SEPARATOR . $file, 0777);
if (!rmdir_recursively($dir . DIRECTORY_SEPARATOR . $file)) return false;
};
}
return rmdir($dir);
}
的問題是,當我發送的內部根某個文件夾,它會刪除此文件夾功能。但是,當我髮根文件夾本身一樣,
rmdir_recursively("./");
它返回象下面
PHP Warning: unlink(.//wp/wp-admin/network) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-admin/user) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content/plugins) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
[07-Oct-2012 02:16:09] PHP Warning: unlink(.//wp/wp-content/plugins/akismet) [<a href='function.unlink'>function.unlink</a>]: No such file or directory in /home/vefa/public_html/deploy.php on line 52
我缺少的是一堆錯誤?
爲什麼不在1行:'exec('rm -fr $ path');' – JvdBerg
@JvdBerg 2問題:它可以在共享服務器上工作嗎?以及如何從刪除中排除腳本本身? – heron
大多數共享主機允許你這樣做。 – JvdBerg