解决方法
查看本教程:
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(); ?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。