将图像保存在公用文件夹中而不是存储laravel 5 [英] save image in public folder instead storage laravel 5

查看:75
本文介绍了将图像保存在公用文件夹中而不是存储laravel 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的头像保存在公共"文件夹中并进行检索.

i wanna save my avatar at "Public" folder and ther retrieve.

好.我可以保存它,但是保存在"storage/app"文件夹中,而不是"public"

ok. i can save it but in "storage/app" folder instead "public"

我的朋友告诉我转到"config/filesystem.php"并对其进行编辑,所以我做到了这一点

my friend told me go to "config/filesystem.php" and edit it ,so i did it like this

 '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');

控制器

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}}">

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

How Can save my image (and file in future) at public folder instead storage?

推荐答案

在config/filesystems.php中,您可以执行此操作... 更改public的根元素

In config/filesystems.php, you could do this... change the root element in public

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

,您可以通过

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

这篇关于将图像保存在公用文件夹中而不是存储laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆