How to delete a folder with PHP?

To delete a file, or a folder and its contents i have compiled a recursive algorithm.
Hope this will be useful for all of you.

read()) {

      // Skip pointers

      if ($entry == '.' || $entry == '..') {

      continue;

      }
       
      // Recurse
      rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);

      }
       
      // Clean up
      $dir->close();

      return rmdir($dirname);

      }

?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *