我正在使用 GridFS,我目前已经让它使用 findOne 显示单个图像,尽管我希望它遍历网格中的所有结果并将它们全部回显到屏幕,这是我正在使用的代码:
<?php
try {
// open connection to MongoDB server
$conn = new Mongo;
// access database
$db = $conn->database;
// get GridFS files collection
$grid = $db->getGridFS();
// retrieve file from collection
header('Content-type: image/png');
$file = $grid->findOne(array('_id' => new MongoId('4fb437dbee3c471b1f000001')));
// send headers and file data
echo $file->getBytes();
exit;
// disconnect from server
$conn->close();
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
?>
谢谢