How PHP Deletes a specified directory
This example describes how PHP deletes a specified directory. Share to everyone for your reference. The specific analysis is as follows:
This code enables the ability to recursively delete subdirectories
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/** * Delete a file, or a folder and its contents * (Recursive algorithm) * @author Aidan Lister * @version 1.0.3 * @param string $dirname Directory to delete * @return BOOL Returns TRUE on success, FALSE on Failure */ function Rmdirr ($dirname) { Sanity check if (!file_exists ($dirname)) { return false; } Simple Delete for a file if (Is_file ($dirname) | | is_link ($dirname)) { Return unlink ($dirname); } Loop through the folder $dir = Dir ($dirname); while (false!== $entry = $dir->read ()) { Skip pointers if ($entry = = '. ' | | $entry = = ' ... ') { Continue } Recurse Rmdirr ($dirname. Directory_separator. $entry); } Clean up $dir->close (); return rmdir ($dirname); } ?> |
http://www.bkjia.com/PHPjc/979231.html www.bkjia.com true http://www.bkjia.com/PHPjc/979231.html techarticle how PHP Deletes a specified directory The example in this article describes how PHP deletes the specified directory. Share to everyone for your reference. The specific analysis is as follows: This code can be implemented recursively delete subdirectories ...