显示BLOB图像Laravel 4 [英] Display BLOB image Laravel 4

查看:165
本文介绍了显示BLOB图像Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql上将png图像添加为BLOB,但是当我尝试检索它们时,我将它们作为文件获得,但无法显示为图像.

I have added png images as BLOB on mysql but when I try to retrieve them, I got them as files but can't display as images.

下面是我的代码.

//控制器

public function post_news(){
    $image = Input::file('image');
    $filename = $image->getClientOriginalName();
    $base64 = base64_encode($filename);
    $news = new News();
    $news->title = Input::get('title');
    $news->description = Input::get('desc');
    $news->image = $filename;
    $news->save();

  return Redirect::to('news')->withErrors(['This news has been added on your database. You may continue!']);

//路线

Route::get('/', function() {
$news = DB::table('news')->get();
return View::make('home2', compact('news'));

});

//观看次数

<?php if (isset($news)) { ?>
            @foreach ($news as $row)
        <div class="img-container">
            <div class="imageOne image"> 
                <?php //dd($row->image); ?>
                <img src="data:image/png;base64,{{ chunk_split(base64_encode($row->image)) }}">  
            </div>
.....

推荐答案

<img src="data:image/png;base64,{{ chunk_split(base64_encode($posts2year->StudentImage)) }}" height="100" width="100">

我在代码中使用了它,并且有效.

I used this in my code and it worked.

这篇关于显示BLOB图像Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆