Novice
Novice

Reputation: 393

Laravel store files with permissions 774

Im loosing mind. I upload files via laravel API, they are stored in folder and file always get permission 644, is there any way how to store files as 775 ?

can i somehow add this to my function ?

 (0755, true, true)

function for store files:

 $result=$request->file('file_path')->store('apiFiles/'.$idParameter);

thanks for any help

Upvotes: 2

Views: 3287

Answers (2)

Babak Asadzadeh
Babak Asadzadeh

Reputation: 1239

you can change permission of file after creating them by chmod command like this:

$result=$request->file('file_path')->store('apiFiles/'.$idParameter);
chmod('file path',0775);

Upvotes: 2

justrusty
justrusty

Reputation: 847

In laravel you can use 'public' or 'private' disks and set the permissions options in the config file filesystems.php

https://laravel.com/docs/8.x/filesystem#permissions

The public visibility translates to 0755 for directories and 0644 for files. You can modify the permissions mappings in your filesystems configuration file:

'local' => [
    'driver' => 'local',
    'root' => storage_path('app'),
    'permissions' => [
        'file' => [
            'public' => 0664,
            'private' => 0600,
        ],
        'dir' => [
            'public' => 0775,
            'private' => 0700,
        ],
    ],
],

You can then store files with specific visibility like it suggests here https://laravel.com/docs/8.x/filesystem#file-visibility

Or you can use the built in php function chmod()

https://www.php.net/manual/en/function.chmod.php

Upvotes: 6

Related Questions