I have in an API in Laravel that stores files
$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 folder
/var/archives
Because these files will be accessed by another application
The third argument of storeAs
tells on 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.
I received this answer on stackoverflow in Portuguese and it worked perfectly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With