Function delete files & folder via PHP

Posted by
function unlinkRecursive($dir, $deleteRootToo){
 if(!$dh = @opendir($dir)){
  return;
 }
 while (false !== ($obj = readdir($dh))){
   if($obj == '.' || $obj == '..'){
     continue;
   }
   if (!@unlink($dir . '/' . $obj)){
    unlinkRecursive($dir.'/'.$obj, true);
   }
 }
 closedir($dh);
 if ($deleteRootToo){
  @rmdir($dir);
 }
 return true;
}

//// call function
if(unlinkRecursive('insert_full_path','yes')){
 echo 'Successful';
}else{
 echo 'Error';
}