简体   繁体   中英

Display BLOB image Laravel 4

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.

Below is my code.

//Controller

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

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

});

//Views

<?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">

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM