代码之家  ›  专栏  ›  技术社区  ›  Arno van Oordt

Laravel 5.5-上载到公用文件夹

  •  0
  • Arno van Oordt  · 技术社区  · 7 年前

    我正在尝试将文件存储在公用文件夹中 storage/app/public/ storage/app/ 文件夹

    如果我理解正确,我应该将可见性设置为“public”,但这似乎没有改变任何事情:

    Storage::put($fileName, file_get_contents($file), 'public');
    

    当我打电话给getVisibility时,我会把它公之于众,这样看起来效果很好:

    Storage::getVisibility($fileName); // public
    

    这些是我的文件系统中的设置。php:

    '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_KEY'),
            'secret' => env('AWS_SECRET'),
            'region' => env('AWS_REGION'),
            'bucket' => env('AWS_BUCKET'),
        ],
    
    ],
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Hamoud    7 年前

    当你打电话的时候 Storage::put ,Laravel将使用默认磁盘,即“本地”。

    本地磁盘在其根目录下存储文件: storage_path('app') . 可见性与文件应存储的位置无关。

    您需要选择 public 将在其根目录下存储文件的磁盘: storage_path('app/public'),

    为此,您需要告诉Laravel在上载文件时使用哪个磁盘。基本上将代码更改为:

    Storage::disk('public')->put($fileName, file_get_contents($file), 'public');