1

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>
.....

1 Answer 1

5
<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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.