I am trying to delete a folder with everything inside it. But it doesn't seem to be working. I have tried lots of different methods. Could someone tell me what I am doing wrong?
<?php
$path = $_POST['Name'];
session_start();
$dir = __DIR__ . "$path";
$di = new RecursiveDirectoryIterator($dir, FilesystemIterator::SKIP_DOTS);
$ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
foreach ( $ri as $file ) {
$file->isDir() ? rmdir($file) : unlink($file);
}
echo "<h1 style='font:normal;'>The Account $path Was deleted</h1>";
?>
Here a solution, you could use
glob
to find all files matching a certain pattern