PHP脚本删除所有内容

I found multiple answers to this but none did work for me.

The content of my directory called "builds" has to be deleted (it includes subfolders and .zip archives) without deleting the "builds" folder itself, located at:

/home/user/public_html/miner/builds/

I'm using this script but it doesn't return anything and content is still there:

    $files = glob('/home/user/public_html/miner/builds/*'); // get all file names
chmod("/home/user/public_html/miner/builds", 0755);
foreach($files as $file){ // iterate files
  if(is_file($file))
    unlink($file); // delete file
}

Try this function to delete all it's files and folders. Here is an example:

function deleteDir($dir) {
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST);
    foreach ($iterator as $path) {
        if ($path->isDir()) {
            rmdir($path->__toString());
        } else {
            unlink($path->__toString());
        }
    }
    rmdir($dir);
}

If you have access to system commands and you running linux you can do this

system("rm -rf ".escapeshellarg($dir));