Laravel 5.5 - 上传到 public 文件夹
Laravel 5.5 - Upload to public folder
我正在尝试将文件存储在 public 文件夹 storage/app/public/
中,但由于某些原因 Laravel 似乎只是将其放在私人 storage/app/
文件夹中。
如果我理解正确,我应该将可见性设置为 'public',但这似乎没有任何改变:
Storage::put($fileName, file_get_contents($file), 'public');
当我调用 getVisibility 时,我得到 public 所以这似乎工作正常:
Storage::getVisibility($fileName); // public
这些是我的设置 filesystems.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'),
],
],
当您调用 Storage::put
时,Laravel 将使用默认磁盘 'local'。
本地磁盘存储文件在其根目录:storage_path('app')
。可见性与文件的存储位置无关。
您需要选择 public
磁盘,它将在其根目录下存储文件:storage_path('app/public'),
为此,您需要告诉 Laravel 在上传文件时使用哪个磁盘。基本上将您的代码更改为:
Storage::disk('public')->put($fileName, file_get_contents($file), 'public');
我正在尝试将文件存储在 public 文件夹 storage/app/public/
中,但由于某些原因 Laravel 似乎只是将其放在私人 storage/app/
文件夹中。
如果我理解正确,我应该将可见性设置为 'public',但这似乎没有任何改变:
Storage::put($fileName, file_get_contents($file), 'public');
当我调用 getVisibility 时,我得到 public 所以这似乎工作正常:
Storage::getVisibility($fileName); // public
这些是我的设置 filesystems.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'),
],
],
当您调用 Storage::put
时,Laravel 将使用默认磁盘 'local'。
本地磁盘存储文件在其根目录:storage_path('app')
。可见性与文件的存储位置无关。
您需要选择 public
磁盘,它将在其根目录下存储文件:storage_path('app/public'),
为此,您需要告诉 Laravel 在上传文件时使用哪个磁盘。基本上将您的代码更改为:
Storage::disk('public')->put($fileName, file_get_contents($file), 'public');