问题描述
最近,我一直在尝试从数据库中检索图像,但是它不起作用.我正在尝试与Laravel进行此操作,但是我很挣扎,所以我决定让Stack Overflow社区看看他们是否对我有解决方案.
Recently I have been trying to retrieve a image from the database, but it will not work. I am trying to do this with Laravel but I am struggling so I decided to ask the Stack Overflow community to see if they had a solution for me.
在Stack Overflow上也有类似的问题.但是我找不到一个答案在寻找的答案.我还浏览了Laracast网站,它对我有帮助,但仍然不够.最后,我阅读了堆栈溢出问题:显示BLOB图像Laravel 4 .但这对我也没有帮助.
There are similar questions like this one on Stack Overflow. But I could not find one where the answers were the one I was looking for. I have also looked on the Laracast website, it helped me a bit but still not enough. Finally, I have read Stack Overflow question: Display BLOB image Laravel 4. But this did not help me as well.
我的控制器:
<?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 [▶]
}
Ì希望给您足够的信息,以便您可以帮助我解决问题.
Ì hope to have given you enough information so that you can help me solve the problem.
推荐答案
将刀片服务器模板图像标签更改为与此类似的内容应该可以解决您的问题.通常我总是将图像保存在传统文件夹中.这就是您网域的窍门.
Changing you blade template image tag to something similar to this, should solve your problem. Usually i would always save images in traditional folders. This does the trick for your domain.
<img src="data:image/jpg;base64, {{ $image }}" />
这篇关于无法从数据库检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!