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 ($의 문서) :
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
그래, 실제로 일어날 해야할지 모르겠지만, src 속성이 PHP 파일에 대한 경로입니다 img 태그를 짐작하지 않습니다 ^^ – tpei
나는 그것이 실제로 어떻게 가능한지 전혀 모른다 ... – Sammaye