簡體   English   中英

顯示BLOB圖像Laravel 4

[英]Display BLOB image Laravel 4

我已經在mysql上將png圖像添加為BLOB,但是當我嘗試檢索它們時,將它們作為文件獲得,但無法顯示為圖像。

下面是我的代碼。

//控制器

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

我在我的代碼中使用了它,並且有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM