这是我的代码,用于将存储在GridFS中的图像显示为HTML页面。
$conn = new MongoClient('SHLY_DBSERVER');
$db = $conn->newdb;
$gridFS = $db->getGridFS('productImages');
$image = $gridFS->find();
$im_array=iterator_to_array($image);
return $im_array;
将$ im_array传递给视图..
foreach ($im_array as $key => $value)
{
$imageFile = $value->getBytes();
$img=base64_encode($imageFile); ?>
<img style="width:300px;margin-left: 5em" class="img-responsive" src="data:image/jpg;charset=utf8;base64,<?php echo $img ?>"/><br>
}
显示正常的网页图片是一种好习惯吗? 我应该去文件系统存储吗?
答案 0 :(得分:0)
对于图像,js,css和附件文件,只应将文件存储在文件系统中,因为您的Web服务器管理客户端和服务器端缓存。