问题
I'm creating a CMS wherein I can upload files(photos, pdf, etc) using Laravel's file upload. What I'm doing differently is that I want to store the file outside my CMS project directory let's say my website's storage folder. BTW I'm creating two different projects
Laravel documentation says that I can change the path where it will be uploaded in the filesystems.php what I did is get the relative path of my website storage folder and paste it here(see below).
'local' => [
'driver' => 'local', //here
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
As expected it's not working. Any help guys?
回答1:
You can add multiple disk in your file system.
Just locate on same website storage folder
Example:
Project 1:
'disks' => [
'custom_folder_1' => [
'driver' => 'custom',
'root' => '../path/to/your/new/storage/folder',
],
]
Project 2:
'disks' => [
'custom_folder_2' => [
'driver' => 'custom',
'root' => '../path/to/your/new/storage/folder',
],
]
the path should be same location.
../path/to/your/new/storage/folder
and then you can use it like:
Storage::disk('custom_folder_1')->put('filename1', $file_content);
Storage::disk('custom_folder_2')->put('filename2', $file_content);
来源:https://stackoverflow.com/questions/57156204/laravel-upload-a-file-to-different-storage-outside-the-project-directory