From d19711851032317ecfb4791241f284046702fb87 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 15 Oct 2002 16:04:38 +0000 Subject: [PATCH] Admin script to brutally delete every file and directory from the Moodle data directory. Will be useful for those on hosting servers without root access. --- admin/delete.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 admin/delete.php diff --git a/admin/delete.php b/admin/delete.php new file mode 100644 index 0000000000..97af1ea0db --- /dev/null +++ b/admin/delete.php @@ -0,0 +1,63 @@ +dataroot; // The directory to delete! + + if (!$sure) { + notice_yesno ("Are you completely sure you want to delete everything inside the directory $deletedir ?", "delete.php?sure=yes", "index.php"); + exit; + } + + if (!$reallysure) { + notice_yesno ("Are you REALLY REALLY completely sure you want to delete everything inside the directory $deletedir (this includes all user images, and any other course files that have been created) ?", "delete.php?sure=yes&reallysure=yes", "index.php"); + exit; + } + + /// OK, here goes ... + + delete_subdirectories($deletedir); + + echo "

Done!

"; + print_continue($CFG->wwwroot); + exit; + + +function delete_subdirectories($rootdir) { + + $dir = opendir($rootdir); + + while ($file = readdir($dir)) { + if ($file != "." and $file != "..") { + $fullfile = "$rootdir/$file"; + if (filetype($fullfile) == "dir") { + delete_subdirectories($fullfile); + echo "Deleting $fullfile ... "; + if (rmdir($fullfile)) { + echo "Done.
"; + } else { + echo "FAILED.
"; + } + } else { + echo "Deleting $fullfile ... "; + if (unlink("$fullfile")) { + echo "Done.
"; + } else { + echo "FAILED.
"; + } + } + } + } + closedir($dir); +} + +?> -- 2.39.5