php delete a folder

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

showing results for - "php delete a folder"
Kayley
21 Jan 2021
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
Clara
26 Mar 2017
1rmdir ( string $dirname , resource $context = ? ) : bool