Laravel文件系统如何基于共享主机路径将图像存储在文件夹中?

时间:2019-11-19 23:11:21

标签: laravel laravel-5 laravel-5.8

在本地计算机上,我将图像存储在public / imgs文件夹中,但是当我使用this method将laravel应用程序部署到共享虚拟主机时,我发现上载任何图像时,它都会存储在应用程序文件夹中,而不是公共的/ publics内的/ imgs。 如何配置我的filesystem.php以将它们保存在pubic_html下?

这是我的旧filesystem.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    /*
    |--------------------------------------------------------------------------
    | Default Cloud Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Many applications store files both locally and in the cloud. For this
    | reason, you may specify a default "cloud" driver here. This driver
    | will be bound as the Cloud disk implementation in the container.
    |
    */

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3", "rackspace"
    |
    */

    'disks' => [

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

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],
        'imagespth' => [
            'driver' => 'local',
            'root'   => 'public_path()', // previously storage_path();
            'visibility' => 'public'
        ],

    ],

];

并且我正在使用Storage :: disk('imagespth')-> put('imgs'。$ pth,$ fl-> get());在控制器中保存图像的方法

0 个答案:

没有答案