将文件存储在 Laravel 5 根文件夹之外

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30576689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:41:10  来源:igfitidea点击:

Storing files outside the Laravel 5 Root Folder

laravellaravel-5

提问by Silvabullet

I am developing a laravel 5 project and storing image files using imagine. I would want to store my image files in a folder outside the project's root folder. I am stuck at the moment The external folder where image files are supposed to be stored, I want to make it accessible via a sub-domain something like http://cdn.example.comLooking towards your solutions.

我正在开发一个 Laravel 5 项目并使用想象存储图像文件。我想将我的图像文件存储在项目根文件夹之外的文件夹中。我现在被困在应该存储图像文件的外部文件夹中,我想通过子域访问它,例如http://cdn.example.com寻找您的解决方案。

回答by MartinJH

The laravel documentationcould give you a helping hand.

laravel文档可以给你伸出援助之手。

Otherwise you could go to config/filesystems.php and add your own custom storage path for both local and production:

否则,您可以转到 config/filesystems.php 并为本地和生产添加您自己的自定义存储路径:

return [

    'default' => 'custom',
    'cloud' => 's3',
    'disks' => [

        'local' => [
            'driver' => 'local',
            'root'   => storage_path().'/app',
        ],

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

        's3' => [
            'driver' => 's3',
            'key'    => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
        ],

        'rackspace' => [
            'driver'    => 'rackspace',
            'username'  => 'your-username',
            'key'       => 'your-key',
            'container' => 'your-container',
            'endpoint'  => 'https://identity.api.rackspacecloud.com/v2.0/',
            'region'    => 'IAD',
        ],

    ],
];

回答by Noob Coder

get ur path name from base_path();function, then from the string add your desired folder location. suppose ur

base_path();函数中获取您的路径名,然后从字符串中添加您想要的文件夹位置。假设你

base_path() = '/home/user/user-folder/your-laravel-project-folder/'

base_path() = '/home/user/user-folder/your-laravel-project-folder/'

So ur desired path should be like this

所以你想要的路径应该是这样的

$path = '/home/user/user-folder/your-target-folder/'.$imageName;

make sure u have the writing and reading permission

确保你有读写权限