Inspire Shahin Inspire Shahin - 15 days ago 6
PHP Question

How to Delete all folder with file in server (cpanel) ? where is my Mistake?

This function execute successfully but it doesn't deleted any folder.

public function ulink(){
$path='/home/doman/public_html/projectname/';
function Delete($path)
{

if (is_dir($path) === true)
{
$files = array_diff(scandir($path), array('.', '..'));

foreach ($files as $file)
{
Delete(realpath($path) . '/' . $file);
}

return rmdir($path);
}

else if (is_file($path) === true)
{
return unlink($path);
}

return false; }

}

Answer
function delfolder($path) {
   $files = array_diff(scandir($path), array('.','..'));
    foreach ($files as $file) {
      (is_dir("$path/$file")) ? delfolder("$path/$file") : unlink("$path/$file");
    }
    return rmdir($path);
} 
Comments