gpt4 book ai didi

Laravel:如何将图像保存到公共(public)文件夹?

转载 作者:行者123 更新时间:2023-12-04 03:08:55 26 4
gpt4 key购买 nike

我无法将用户图像上传到我的公共(public)文件夹。文件名生成正确,并将名称保存到我的数据库中,除了 iamge 本身拒绝保存到我的公共(public)文件夹中。我做错了什么?

  public function update_avatar(Request $request) {
if($request->hasFile('avatar')) {

$avatar = $request->file('avatar');
$filename = time() . "." . $avatar->getClientOriginalExtension();

Image::make($avatar)->resize(300,300)->save(public_path('/uploads/'.$filename)); ==> This is causing me errors

user = Auth::user();
$user->avatar = $filename;
$user->save();

}

最佳答案

The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments.

To create the symbolic link, you may use the storage:link Artisan command:

php artisan storage:link

https://laravel.com/docs/5.5/filesystem

关于Laravel:如何将图像保存到公共(public)文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46710275/

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