Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to set permissions for an uploaded file when using store() or putFile()?

From the docs: https://laravel.com/docs/9.x/filesystem#file-uploads

I can upload a file from the request using either:

$path = $request->file('avatar')->store('avatars');

or

$path = Storage::putFile('avatars', $request->file('avatar'));

The docs also mention how to set permissions for files: https://laravel.com/docs/9.x/filesystem#file-visibility

Which is to set the permissions for public or private in the config, then use put() method. But when I get files from the request I need to use putFile() or store(), not put(), so how can I set permission in this case?

Also, if I add permissions to my disk in config/filesystems.php:

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('files'),
            'throw' => true,
            'permissions' => [
                'file' => [
                    'public' => 0777,
                    'private' => 0777,
                ],
                'dir' => [
                    'public' => 0777,
                    'private' => 0777,
                ],
            ],
        ],

Does the method store() use the private keys? (Because I know there is also a method called storePublicly, so maybe store without anything means "privately" explicitly?)

0 likes
1 reply
Ligonsker's avatar

Update: I tested and the store() method uses the private key in the local disk array, so I finally found a way to be able to view files locally during development - I add the following permissions block to my local disk:

        'local' => [
            'driver' => 'local',
            'root' => storage_path('uploads'),
            'throw' => true,
            'permissions' => [
                'file' => [
                    'public' => 0644,
                    'private' => 0660,
                ],
                'dir' => [
                    'public' => 0755,
                    'private' => 0770,
                ],
            ],
        ],

Please or to participate in this conversation.