Php 将图像访问到存储器并显示到刀片视图中

Php 将图像访问到存储器并显示到刀片视图中,php,html,laravel,Php,Html,Laravel,我是新来的,下面的图片是代码。 我想将图像从存储访问到刀片视图如何实现这一点 //在我的控制器中 //保存到数据库 $post=新员额; $post->title=$request->input('title'); $post->body=$request->input('body'); $post->subcategory_id=内爆(',',$request->input('subcategory_id'); $post->user\u id=auth()->user()->id; $pos

我是新来的,下面的图片是代码。 我想将图像从存储访问到刀片视图如何实现这一点

//在我的控制器中
//保存到数据库
$post=新员额;
$post->title=$request->input('title');
$post->body=$request->input('body');
$post->subcategory_id=内爆(',',$request->input('subcategory_id');
$post->user\u id=auth()->user()->id;
$post->content=$fileNameToStore;
$post->save();
//保存到存储器
$post=Image::make(
$request->file('content')->getRealPath())->save('public/content',$fileNameToStore);
$post->resize(300300);
$post->text('敏捷的棕色狐狸跳过懒狗',10,10);
$post->save();
//叶片视图
内容“style=“width:100%”

更改
.blade.php
文件如下:

@php
    echo'<img src="content/'.$post->content.'" style="width: 100%">';
@endphp
@php
回显“内容”。“style=”宽度:100%“>”;
@endphp
  • 无需写入
    public
    目录名
  • 您已将图像保存在
    内容
    文件夹中

更改
.blade.php
文件如下:

@php
    echo'<img src="content/'.$post->content.'" style="width: 100%">';
@endphp
@php
回显“内容”。“style=”宽度:100%“>”;
@endphp
  • 无需写入
    public
    目录名
  • 您已将图像保存在
    内容
    文件夹中

使用资产功能如下


content)“style=“width:100%”>
使用资产功能如下


content)“style=“width:100%”>

我不知道您的代码的主要目的,但知道将图像存储在Laravel中以将其存储在存储磁盘(Laravel项目的存储文件夹)中的一般最佳做法, 这是一个选择和上载我在项目中使用的多个文件的示例,可能会对您有所帮助

$files = [];
      if($request->hasfile('files_to_upload')){
         foreach($request->file('files_to_upload') as $file){
             $name = time().rand(1,100).'.'.$file->extension();
             $files[]= storage_path().'/app/'.$file->storeAs('files', $name);  
         }
      }

我不知道你的代码的主要目的,但一般的最佳做法是将图像存储在Laravel中,并将其存储在存储磁盘(Laravel项目的存储文件夹)中, 这是一个选择和上载我在项目中使用的多个文件的示例,可能会对您有所帮助

$files = [];
      if($request->hasfile('files_to_upload')){
         foreach($request->file('files_to_upload') as $file){
             $name = time().rand(1,100).'.'.$file->extension();
             $files[]= storage_path().'/app/'.$file->storeAs('files', $name);  
         }
      }