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); } } $path="path/to/your/folder"; rrmdir($path);
If you want to remove directory using php then you have to use rmdir function to remove directory but remember first delete files you can use unlink command to remove file