将图像保存在公共文件夹中,而不是存储Laravel 5



我想将我的化身保存在" public"文件夹中,然后检索。

好的。我可以保存它,但在"存储/应用"文件夹中" public"

我的朋友告诉我去" 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');

控制器

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中,您可以做到这一点...更改public

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

您可以通过

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

您可以将磁盘选项传递给IlluminateHttpUploadedFile类的方法:

$file = request()->file('image');
$file->store('toPath', ['disk' => 'public']);

或者您可以创建新的文件系统磁盘,然后可以将其保存到该磁盘。

您可以在config/filesystems.php中创建新的存储光盘:

'my_files' => [
    'driver' => 'local',
    'root'   => public_path() . '/myfiles',
],

在控制器中:

$file = request()->file('image');
$file->store('toPath', ['disk' => 'my_files']);

您需要使用:

将存储目录链接到公共文件夹
php artisan storage:link

完成此操作后,要在视图中显示它:

{{ asset('storage/file.txt') }}

或您的情况:

<img src="{{ asset('storage/app/' . $patch) }}">

您需要

php artisan storage:link

商店文件

$path = $request()->file('file')->store('images', 'public');

路径=域/存储/图像/filename.txt

文件将保存在存储/app/public/images

最新更新