Laravel将文件上传到项目目录外的其他存储

Laravel将文件上传到项目目录外的其他存储

本文介绍了Laravel将文件上传到项目目录外的其他存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在创建一个CMS,其中可以使用Laravel的文件上传功能来上传文件(照片,pdf等).我正在做的不同的是,我想将文件存储在CMS项目目录之外,比方说我网站的存储文件夹.顺便说一句,我正在创建两个不同的项目

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文档说,我可以更改将其上传到filesystems.php中的路径.我所做的就是获取网站存储文件夹的相对路径并将其粘贴到此处(见下文).

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?

推荐答案

您可以在文件系统中添加多个磁盘.

You can add multiple disk in your file system.

只需找到同一网站的存储文件夹

Just locate on same website storage folder

示例:

项目1:

'disks' => [
        'custom_folder_1' => [
            'driver' => 'custom',
            'root'   => '../path/to/your/new/storage/folder',
        ],
]

项目2:

'disks' => [
        'custom_folder_2' => [
            'driver' => 'custom',
            'root'   => '../path/to/your/new/storage/folder',
        ],
]

路径应该在同一位置.

../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);

这篇关于Laravel将文件上传到项目目录外的其他存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:34