无法从数据库中检索图像

时间:2019-06-30 17:49:50

标签: php laravel

最近我一直在尝试从数据库中检索图像,但是它不起作用。我正在尝试与Laravel一起执行此操作,但是我很挣扎,所以我决定让Stack Overflow社区看看他们是否对我有解决方案。

在Stack Overflow上也有类似的问题。但是我找不到答案在哪里。我也浏览了Laracast网站,它对我有帮助,但仍然不够。最后,我阅读了堆栈溢出问题:Display BLOB image Laravel 4。但这对我也没有帮助。

我的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\gallerijs;

class GalerijController extends Controller
{
    public function Retrieve(){
    $g = gallerijs::find(1);
    dd($g);
    $image = chunk_split(base64_encode($g->afbeelding));
    return view('gallerij')->with('image', $image);
}
}

我的观点:

@extends ('Layout')
@section('title')
    Galerij
@endsection

@section('content')


<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

</head>
<body>

<div id="demo" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>

  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="{{asset('Pictures/'.$image)}}" alt="Los Angeles" width="1100" height="500">
    </div>
    <div class="carousel-item">
      <img src="{{asset('Pictures/loremipsum2.jpg')}}" alt="Chicago" width="1100" height="500">
    </div>
    <div class="carousel-item">
      <img src="{{asset('Pictures/loremipsum3.jpg')}}" alt="New York" width="1100" height="500">
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
</div>

</body>
</html>


@endsection

我的dd($g)返回的内容:

gallerijs {#232 ▼
  #fillable: array:2 [▶]
  #connection: "mysql"
  #table: "gallerijs"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:4 [▶]
  #original: array:4 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]
}

Ì希望给您足够的信息,以便您可以帮助我解决问题。

1 个答案:

答案 0 :(得分:0)

将刀片模板图像标签更改为与此类似的内容,应该可以解决您的问题。通常我总是将图像保存在传统文件夹中。这就是您网域的窍门。

    <img src="data:image/jpg;base64, {{ $image }}" />
相关问题