Storing files outside the Laravel 5 Root Folder

2019-02-22 11:07发布

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.com Looking towards your solutions.

2条回答
唯我独甜
2楼-- · 2019-02-22 11:36

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

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

查看更多
戒情不戒烟
3楼-- · 2019-02-22 11:37

The laravel documentation could give you a helping hand.

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

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',
        ],

    ],
];
查看更多
登录 后发表回答