Laravel storage - access denied (different owner)

64 views Asked by At

I have two different points which I need to write to the same log file, one is a concole commando file and another is a web controller.

In both cases I use append command:

Storage::disk('local')->append($logfilePath, $content);

The problem is that file is created with permissions 664 (-rw-r--r--), so depend on the process that creates the file, the other one cannot write to it.

Is there any way to create file using Storage class with permission 666?

1

There are 1 answers

0
guyaloni On BEST ANSWER

I share here the solution I found:

In config/filesystems.php I added the following code to local:

        'local' => [
            'permissions' => [
                'file' => [
                    'public' => 0666,
                    'private' => 0600,
                ],
                'dir' => [
                    'public' => 0755,
                    'private' => 0700,
                ],
            ],
        ],

When creating a new file I specify the permissions I want the file to have:

if (!Storage::disk('local')->exists($logFilePath)) {
    Storage::disk('local')->put($logFilePath, $content, 'public');
} else {
    Storage::disk('local')->append($logFilePath, $content);
}

Notice that when using append, you cannot set file permissions, even if it is not created yet.