This article mainly introduces php recursive deletion of specified folders. The example summarizes two common recursive deletion of folders, which is of great practical value, for more information about how to recursively delete a specified folder in php, see the examples in this article. Share it with you for your reference. The details are as follows:
Method 1:
function recursiveDelete($dir){ if ($handle = @opendir($dir)) { while (($file = readdir($handle)) !== false) { if (($file == ".") || ($file == "..")) { continue; } if (is_dir($dir . '/' . $file)) { // call self for this directory recursiveDelete($dir . '/' . $file); } else { unlink($dir . '/' . $file); // remove this file } } @closedir($handle); rmdir ($dir); }}
Method 2:
/* Custom deletion function, which can delete files and recursively delete folders */function my_del ($ path) {if (is_dir ($ path )) {$ file_list = scandir ($ path); foreach ($ file_list as $ file) {if ($ file! = '.' & $ File! = '.. ') {My_del ($ path. '/'. $ file) ;}@ rmdir ($ path); // This method does not need to be used to determine whether the folder is empty. // no matter whether the folder is empty at the beginning, all are empty} else {@ unlink ($ path); // it is best to use @ to block the warning error in the two places and look at it.} $ path = 'd: /technical documentation-replicas '; // the folder to be deleted // if the php file is not ANSI but UTF-8 mode, // and the folder to be deleted contains Chinese characters, transcoding before calling a function // $ path = iconv ('utf-8', 'gb2312', $ path); my_del ($ path );
I hope this article will help you with php programming.