Laravel Storage :: disk('local')-> put在项目文件之外创建一个文件

时间:2019-02-15 13:14:11

标签: laravel docker storage

我正在使用docker运行我的项目。 我正在使用功能

   Storage::disk('local')->put("/algorithms/".$this->algorithm_id."/newfile.csv", $csv_newfile->__toString());

我想将此文件存储为var/www/html/Laravel/resources/app/algorithms/algorithm_id/newfile 但是它将其从项目文件夹存储到一个目录。 所以 我的项目坐在 /var/www/html/Laravel 但它会在/var/www/html/algorithms/algorithm_id/newfile中创建此文件 我可能已经在/var/www/html(?)中设置了项目根目录,但是我找不到在哪里做的。 有人可以解释可能是什么问题吗?

这是我的/config/filesystems.php文件

<?php

返回[

/*
|--------------------------------------------------------------------------
| 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", "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'),
    ],

],

];

1 个答案:

答案 0 :(得分:0)

我遇到了与您相似的问题。这是对我有用的解决方案:

创建一个新磁盘放置在目录中

'web_site_root' => [
            'driver' =>'local',
            'root' => base_path();
        ]

您要删除第一个/

代码:

   Storage::disk('web_site_root')->put("algorithms/".$this->algorithm_id."/newfile.csv", $csv_newfile->__toString());

我不知道为什么,但是就我而言,第一个/使文件也保存在根目录中。