douba1067 2018-10-10 13:12
浏览 53

在视图中显示存储中的图像

I have a form with multiple fields which stores information including an image upload. There is also an edit view:

Route::PUT('/link/{link}', function (Request $request, Link $link) {
  $request->validate([
    'name' => 'required|max:255',
    'title' => 'required|max:255',
    'cell' => 'required|max:255',
    'tel' => 'required|max:255',
    'email' => 'required|max:255',
    'website' => 'required|url|max:255',
    'location' => 'required|max:255',
    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
  ]);

  $img = $request->file('image');

  $newfilename = $request->name;

  $img->move(public_path("/uploads"), $newfilename);

  $link->update($request->all());

  return redirect('/');
});

The initial submit and edit works fine along with changing the image file name and storing it in the uploads folder.

The path generated being:

public/uploads/exampleFileName.jpg

The problem here is when it comes to displaying the image in the home view. The code below generates a 404 not found with an additional /tmp/ path which I have no idea about where it comes from.

Code in home view:

@foreach ($links as $link)
    <div class="link-box">
      <h5 class="off-white-txt">Card [# {{ $link->id }}]</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Name: </span>{{ $link->name }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Title: </span>{{ $link->title }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Cell: </span>{{ $link->cell }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Tel: </span>{{ $link->tel }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Email: </span>{{ $link->email }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Website: </span>{{ $link->website }}</h5>
      <h5 class="off-white-txt"><span class="pool-blue-txt">Location: </span>{{ $link->location }}</h5>

  <img src="{{url('uploads'.$link->image) }}" class="off-white-txt">
</div>

The error message in the console:

GET http://192.168.10.10/uploads/tmp/phpdtnTcw 404 (Not Found)

My question is the following; How could I edit my code to point to the correct path and display the image?

Thank you in advance.

  • 写回答

4条回答 默认 最新

  • doucaishi0077 2018-10-10 13:16
    关注

    if you are using storage folder to save images then you should use Storage::url

    make sure to run command php artisan storage:link

      <img src="{{ Storage::url($link->image) }}" class="off-white-txt">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目