gpt4 book ai didi

php - 将图像保存在公用文件夹中而不是存储 laravel 5

转载 作者:可可西里 更新时间:2023-11-01 12:23:45 26 4
gpt4 key购买 nike

我想将我的头像保存在“Public”文件夹中然后检索。

好的。我可以将它保存在“storage/app”文件夹中而不是“public”

我的 friend 告诉我去“config/filesystem.php”并编辑它,所以我就这样做了

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

仍然没有变化。

这里是我的简单代码

路线:

Route::get('pic',function (){
return view('pic.pic');
});
Route::post('saved','test2Controller@save');

Controller

public function save(Request $request)
{
$file = $request->file('image');
//save format
$format = $request->image->extension();
//save full adress of image
$patch = $request->image->store('images');

$name = $file->getClientOriginalName();

//save on table
DB::table('pictbl')->insert([
'orginal_name'=>$name,
'format'=>$base,
'patch'=>$patch
]);

return response()
->view('pic.pic',compact("patch"));
}

查看:

{!! Form::open(['url'=>'saved','method'=>'post','files'=>true]) !!}
{!! Form::file('image') !!}
{!! Form::submit('save') !!}
{!! Form::close() !!}

<img src="storage/app/{{$patch}}">

如何将我的图像(以及将来的文件)保存在公用文件夹而不是存储?

最佳答案

在 config/filesystems.php 中,你可以这样做......公开更改根元素

'disks' => [
'public' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
]
]

你可以通过

访问它
Storage::disk('public')->put('filename', $file_content);

关于php - 将图像保存在公用文件夹中而不是存储 laravel 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42562203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com