0
我在oder中使用PHP來遞歸地刪除一個目錄。 當調用這個函數:PHP本身內部調用函數磚
function deleteDir($dirPath) {
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
使用此行:
deleteDir("dir_to_be_deleted_recursively/");
它放在這裏錯了:
deleteDir($file);
(當功能檢測到它正試圖在目錄中的目錄刪除,它再次調用該函數,但爲該目錄)
Thi s是我正在測試它的目錄:
dir_to_be_deleted_recursively/
dir1/
subdir1/
file1.txt
subdir2/
file2.txt
subdir3/
file3.txt
注:我沒有收到錯誤,只是一個空白頁。
確保您已啓用錯誤報告。添加'ini_set('display_errors',1); error_reporting(E_ALL);'到腳本的最頂部並重試。 –
謝謝,現在我得到了:'警告:爲foreach()提供的無效參數'和很多'Warning:directory not empty'警告 – Laurent