fixDirectoryPermission example

public function checkSingleDirectoryPermissions(string $directory, bool $fixPermission = false): array
    {
        $errors = [];

        if (!is_dir($directory) && !mkdir($directory) && !is_dir($directory)) {
            $errors[] = $directory;

            return $errors;
        }
        if ($fixPermission && !is_writable($directory)) {
            $fileInfo = new \SplFileInfo($directory);
            $this->fixDirectoryPermission($fileInfo);
        }
        if (!is_writable($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        return $errors;
    }

    private function fixDirectoryPermission(\SplFileInfo $fileInfo): void
    {

        $errors = [];

        if (!is_dir($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        if ($fixPermission && !is_writable($directory)) {
            $fileInfo = new SplFileInfo($directory);
            $this->fixDirectoryPermission($fileInfo);
        }

        if (!is_writable($directory)) {
            $errors[] = $directory;

            return $errors;
        }

        return $errors;
    }

    
Home | Imprint | This part of the site doesn't use cookies.