PHP – Delete Directory and Content Recursively

The given PHP example delete the directory and its content recursively.

Code Example:
<?php
function rrmdir($dir){
	if (is_dir($dir)){
		$objects = scandir($dir);
		foreach ($objects as $object){
			if ($object != "." && $object != ".."){
				if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
			}
		}
		reset($objects);
		rmdir($dir);
	}
}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

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