我目前使用兩個文件顯示所有圖像,一個獲取內容和第二顯示它(或嘗試過)MongoDB的GridFS的
我需要做的是通過存儲在GridFS的顯示這些圖像迭代總之,我可以得到的文件名進行迭代,並且文件名是查找的paramiter內,但它不工作,我只是得到一個破碎的形象,這裏是代碼:
Display.php的
<?php
// open connection to MongoDB server
$conn = new Mongo;
// access database
$db = $conn->database;
// get GridFS files collection
$grid = $db->getGridFS();
$cursor = $grid->find();
foreach ($cursor as $obj) { // iterate through the results
$filename = $obj->getFilename().'<br/>';
echo "<img src='newupload.php?filename=".$filename."'>";
echo $filename;
}
?>
這裏是進入gridFS的那個
<?php
$filename = $_GET['filename'];
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->find(array('filename' => $filename));
// 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());
}
?>
非常感謝