假设我的服务器有 4GB 的内存并且我上传了一个大小为 5GB 的文件。如何使用 gridfs 下载该文件。以下站点声明http://www.php.net/manual/en/mongogridfsfile.getbytes.php 如果您的文件比内存大,那么它就是一个问题,但没有说明解决方案。
任何人都可以对此有任何解决方案。我使用这个演示代码来访问一个文件。
<?php
// Connect to Mongo and set DB and Collection
$mongo = new Mongo();
$db = $mongo->myfiles;
// GridFS
$gridFS = $db->getGridFS();
// Find image to stream
$file = $gridFS->findOne("win.tar");
// Stream image to browser
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"win.tar\"");
echo $file->getBytes();
?>