Warning: unlink () Resource is temporarily unavailable

When I call rrmdir()to delete the directory and all its subfolders, then it gives a warning:

"Attention: Break the connection (C: \ congreaaws \ TMP \ mfpXeLhshG6puztQbamygpB1CqowIzL7ajS5Se8a \ 12323 \ 076a12b3-9052-404a-9cd1-cfb62adf62c1 \ mod.pptx): Resource cpf \ timepresre \ timephp \ timepre \\

function rrmdir($dir) {
  // echo $dir; exit;
    if (is_dir($dir)) {
        $objects = scandir($dir);
        foreach ($objects as $object) {
            if ($object != "." && $object != "..") {
                if (is_dir($dir . "/" . $object))
                    rrmdir($dir . "/" . $object);
                else
                    unlink($dir . "/" . $object);
            }
        }
        rmdir($dir);
    }
}

The same function works in centos, but it does not work in windows. I used the iis server to run php.

Thanks in advance

+4
source share
1 answer

Use the following code, I'm sure it will solve your problems.

Add this function to your function file

function delete_directory($dirPath){
        $dir = $dirPath;   
        if(is_dir($dir)){
            $files = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST
            );
            foreach($files as $file){
                if ($file->isDir()){
                    rmdir($file->getRealPath());
                }else{
                    unlink($file->getRealPath());
                }
            }
            rmdir($dir);
        }
    }

HOW TO USE

delete_directory ($ dir);

0
source

Source: https://habr.com/ru/post/1692025/


All Articles