protected function recursiveDelete($dir, $del = 0)
    {

        if (substr($dir, 0, 1) == '/') {
            throw new \Exception("You cannot delete root directories");
        }

        $iterator = new \RecursiveDirectoryIterator($dir);
        foreach (new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            $name = $file->getFilename();
            if ($file->isDir() && $name != '.' && $name != '..') {
                rmdir($file->getPathname());
            } elseif ($file->isFile()) {
                unlink($file->getPathname());
            }
        }

        if ($del == 1) {
            rmdir($dir);
        }
    }