/ Published in: PHP
This isn't my code, but just thought I would share, since it took me so long to find. This is a function to delete a folder, all sub-folders, and files in one clean move.
Just tell it what directory you want deleted, in relation to the page that this function is executed. Then set $empty = true if you want the folder just emptied, but not deleted. If you set $empty = false, or just simply leave it out, the given directory will be deleted, as well.
Just tell it what directory you want deleted, in relation to the page that this function is executed. Then set $empty = true if you want the folder just emptied, but not deleted. If you set $empty = false, or just simply leave it out, the given directory will be deleted, as well.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function deleteAll($directory, $empty = false) { } return false; return false; } else { if($contents != '.' && $contents != '..') { $path = $directory . "/" . $contents; deleteAll($path); } else { } } } if($empty == false) { return false; } } return true; } } ?>
URL: http://php.net/manual/en/function.rmdir.php