如何在MongoDB数据库中插入图像并使用PHP将其显示在网页上?

时间:2016-07-24 17:36:32

标签: php image mongodb insert

我正在编写一些代码来在网页上显示图像。下一个代码显示网络中的数据,但不显示图像。我可以更改什么来显示网络中的图像。

<?php

$m = new MongoClient();
$db = $m->selectDB("local");

// Get the users collection
//$c_faq = $db->faq;

// GridFS
$grid = $db->getGridFS();

// The file's location in the File System
$path = "C:\Wamp\Apache\htdocs\knowledge\scripts";

$filename = "\imagen1.png";

// Note metadata field & filename field
$storedfile = $grid->storeFile($path . $filename,
         array("metadata" => array("filename" => $filename),
         "filename" => $filename));


// Return newly stored file's Document ID
echo $storedfile;


// GridFS
$gridFS = $db->getGridFS();     

// Find image to stream
$image = $gridFS->findOne("\imagen1.png");

// Stream image to browser
header('Content-type: imagen.png');
echo $image->getBytes(); 

?>

0 个答案:

没有答案