我試圖使用GridFS將圖像保存到MondoDB集合。爲了驗證這一點,我做了以下內容:MongoDB GridFS圖像加載不正確
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
// open connection
$m = new MongoClient();
$db = $m->selectDB('ImageDatabase');
$gridUploads = $db->getGridFS('images');
// save image
$fileName = 'C:\Users\Thomas\Pictures\commits.png';
$gridUploads->storeFile($fileName);
// load image
$doc = $gridUploads->findOne($fileName);
// dsplay image
header('Content-type: image/png');
echo $doc->getBytes();
?>
</body>
</html>
這應該將圖像上傳到集合,然後獲得從集合相同的圖像,並顯示它。
在此之後收集的內容是:
{
"_id" : ObjectId("52a6fcdd1dc38f0c3c0016bf"),
"filename" : "C:\\Users\\Thomas\\Pictures\\commits.png",
"uploadDate" : ISODate("2013-12-10T11:37:01.000Z"),
"length" : 179952,
"chunkSize" : 262144,
"md5" : "768d618923442668ca2a60f02be59d52"
}
的print_r($ DOC):
MongoGridFSFile Object
(
[file] => Array
(
[_id] => MongoId Object
(
[$id] => 52a6fcdd1dc38f0c3c0016bf
)
[filename] => C:\Users\Thomas\Pictures\commits.png
[uploadDate] => MongoDate Object
(
[sec] => 1386675421
[usec] => 0
)
[length] => 179952
[chunkSize] => 262144
[md5] => 768d618923442668ca2a60f02be59d52
)
[gridfs:protected] => MongoGridFS Object
(
[w] => 1
[wtimeout] => 10000
[chunks] => MongoCollection Object
(
[w] => 1
[wtimeout] => 10000
)
[filesName:protected] => images.files
[chunksName:protected] => images.chunks
)
[flags] => 0
)
然而結果的主體內容是:
<img style="-webkit-user-select: none" src="http://localhost/path-to/the-script.php">
任何ideads爲什麼?
謝謝!
結果內容是圖片標籤? – Sammaye
是的,我不知道應該發生什麼,但我想一個img標籤,其中src屬性是php文件的路徑不是它^^ – tpei
我真的不知道這是怎麼可能的... – Sammaye