Php Recursive method Summary for deleting a specified folder
PHP recursively deletes the specified folder method:
below for you to introduce the PHP recursive deletion of the specified folder method, the example summarizes the two commonly used recursive delete folder skills, very practical value, the need for friends can refer to the following
This article summarizes two ways that PHP recursively deletes a specified folder. Share to everyone for your reference. Specific as follows:
Method One:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 |
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 Two:
?
1 2 3 4 5 6 7 8 9 13 /p> + + / / / + + + + 25 + + $ + + |
/* Custom Delete functions that 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 have to determine whether the folder is empty, Because when the folder is empty at the beginning, it's empty when you get here. } Else { @unlink ($path); These two places best still have to use @ Shielding warning error, watching the frustration } } $path = ' d:/Technical document-copy '; The folder to delete If the PHP file is not ANSI, but UTF-8 mode, and the folder you want to delete contains kanji characters, you need to transcode before calling the function $path =iconv (' utf-8 ', ' gb2312 ', $path); My_del ($path); |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/987106.html www.bkjia.com true http://www.bkjia.com/PHPjc/987106.html techarticle php Recursive removal of the specified folder method summary php Recursive deletion of the specified folder method: The following is the way you introduced the PHP recursive deletion of the specified folder, the example summarizes the two common ...