我使用 PHP 成功地将图像文件存储在 MongoDB 中,当我从 Mongo db 检索图像时遇到了一些问题,谁能给出解决方案这是我的代码:
<?php
$m = new Mongo();
$db = $m->selectDB("example");
$article = $db->articles;
$files = $article->find();
$gridFS = $db->getGridFS();
?>
<table>
<?php
$i=1;
foreach ($files as $storedfiles) {
?>
<tr>
<td width="30%"><strong><?php echo $i; ?></strong></td>
<td width="70%">
<?php //echo $storedfiles["_id"]; ?>
<?php echo "Id :".$storedfiles["_id"]; ?>
<?php echo "Title :".$storedfiles["title"]; ?>
<?php echo "Keywords :".$storedfiles["keywords"]; ?>
<?php echo "Image :".$storedfiles["image"]; ?>
<?php $image = $gridFS->findOne(array('_id' => new MongoId($storedfiles["image"])));
header('Content-type: image/jpg;');
echo $image->getBytes();
?>
</td>
</tr>
<?php
$i++;
}
?>
</table>