3
我該如何保存我的MongoDB上的文件?
我使用PHP和它似乎並沒有被任何信息..
此外,如果你coud給我一些例子,知道如何保存和下載這些FLES我會很感謝如何使用PHP在MongoDB上保存文件?
我該如何保存我的MongoDB上的文件?
我使用PHP和它似乎並沒有被任何信息..
此外,如果你coud給我一些例子,知道如何保存和下載這些FLES我會很感謝如何使用PHP在MongoDB上保存文件?
檢查本教程出:http://learnmongo.com/posts/getting-started-with-mongodb-gridfs/
粘貼一些代碼有它的答案:
<?php
// Connect to Mongo and set DB and Collection
$mongo = new Mongo();
$db = $mongo->myfiles;
// GridFS
$grid = $db->getGridFS();
// The file's location in the File System
$path = "/tmp/";
$filename = "03-smbd-menu-screen.mp3";
// 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;
?>
獲取文件退了出來:
<?php
// Connect to Mongo and set DB and Collection
$mongo = new Mongo();
$db = $mongo->myfiles;
// GridFS
$gridFS = $db->getGridFS();
// Find image to stream
$image = $gridFS->findOne("chunk-screaming.jpg");
// Stream image to browser
header('Content-type: image/jpeg');
echo $image->getBytes();
?>
太好了。非常感謝你=) – fnaquira 2012-03-02 14:01:07
偉大的...你可以請告訴我使用getBytes .... – 2013-02-25 13:57:26