是否有任何方法可以显示GridFS中的图像,而不是在html图像标记中使用base64编码


Is there any method to display images from GridFS rather than base64 encoding in html image tag

这是我的代码显示存储在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>

     }

是一个很好的做法,以显示正常的网页图像?我应该使用文件系统存储吗?

对于图像,js, css和附件文件,您应该将文件存储在文件系统中,因为您的web服务器管理客户端和服务器端缓存。