我在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">
我在我的代码中使用了这个工作。