+}
+
+
+function deleteDirectoryContents($dir) {
+ error_log("Deleting directory contents at $dir");
+ if (!is_dir($dir)) {
+ echo "The provided path is not a directory.";
+ return false;
+ }
+
+ // Open the directory
+ $handle = opendir($dir);
+ if ($handle === false) {
+ echo "Failed to open the directory.";
+ return false;
+ }
+
+ // Loop through the directory contents
+ while (($item = readdir($handle)) !== false) {
+ // Skip the special entries "." and ".."
+ if ($item == "." || $item == "..") {
+ continue;
+ }
+
+ $itemPath = $dir."/".$item;
+
+ // If the item is a directory, recursively delete its contents
+ if (is_dir($itemPath)) {
+ deleteDirectoryContents($itemPath);
+ // Remove the empty directory
+ rmdir($itemPath);
+ } else {
+ // If the item is a file, delete it
+ unlink($itemPath);
+ }
+ }
+
+ // Close the directory handle
+ closedir($handle);
+
+ return true;