/ Published in: PHP

Here’s a snippet that can help you to remove a non-empty directory from the server. It’s a recursive function that deletes the directory with its files, folders and sub-folders.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
1. <?php 2. function delete_directory($dir) 3. { 5. { 7. 9. if ($file != "." && $file != "..") { 10. 12. { 14. { 15. delete_directory($dir.$file.'/'); // Not empty? Delete the files inside it 16. } 17. } 18. else 19. { 21. } 22. } 23. } 25. 27. } 28. 29. } 30. 31. $dir = '/home/path/to/mysite.com/folder_to_delete/'; // IMPORTANT: with '/' at the end 32. 33. $remove_directory = delete_directory($dir); 34. ?>
Comments
