Save files with storeAs outside the Storage folder

1

I have a API in Laravel a file store

$request->file("file$i")->storeAs('categories', $nameFile)

As it stands it stores the data correctly in the address

/var/www/html/apiapp/storage/app/public/categories

But I would like to save these files in the

/var/archives

Because these files will be accessed by another application

    
asked by anonymous 04.01.2018 / 19:45

1 answer

2

The third argument of storeAs says in which storage disk the file should be saved

$path = $request->photo->storeAs('images', 'filename.jpg', 's3');

So, create a new disk in config/filesystem.php and point it to /var/archives

'disks' => [

    // ...

    'archive' => [
        'driver' => 'local',
        'root' => '/var/archives',
    ],

    // ...

In the code:

$request->file("file$i")->storeAs('categories', $nameFile, 'archive')

Ensure that the user running the webserver has permission to save to that folder on disk as well.

Another alternative is to share an external storage , such as AWS S3 for example. The configuration for this follows the same idea.

    
04.01.2018 / 21:32