php delete directory

Solutions on MaxInterview for php delete directory by the best coders in the world

showing results for - "php delete directory"
Serena
01 Jul 2016
1function deleteDirectory($dir) {
2    if (!file_exists($dir)) {
3        return true;
4    }
5
6    if (!is_dir($dir)) {
7        return unlink($dir);
8    }
9
10    foreach (scandir($dir) as $item) {
11        if ($item == '.' || $item == '..') {
12            continue;
13        }
14
15        if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
16            return false;
17        }
18
19    }
20
21    return rmdir($dir);
22}
23
Lena
25 May 2018
1rmdir ( string $dirname , resource $context = ? ) : bool