Save files with storeAs out of Storage folder

Asked

Viewed 1,599 times

2

I have in an API in Laravel for file storage

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

As it is it stores the data correctly in the address

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

However I would like to save these files in the folder

/var/archives

Because these files will be accessed by another application

1 answer

4


The third argument of storeAs tells you which one Storage disk the file must be saved

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

So create a new disk in config/filesystem.php and point him 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 who runs the webserver you have permission to save this folder to disk as well.

Another alternative is to share a Storage external, like AWS S3 for example. The setting for this follows the same idea.

  • 1

    VLW same guy, worked perfectly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.