簡體   English   中英

使用PHP從Mongodb下載大文件

[英]Downloading Large file from Mongodb using PHP

我使用 php 在 Mongodb 中存儲了超過 250MB 的壓縮文件。 但我無法取回它。 它只顯示“0”號。 下面是我的代碼。

$id = $_GET['id'];
require 'dbconnection.php';


$mongo = DBConnection::instantiate();
$gridFS = $mongo->database->getGridFS();

$object = $gridFS->findOne(array('_id' => new MongoId($id)));
header("Content-Transfer-Encoding: binary");
header('Content-type: '.$object->file['filetype']);
header('Expires: 0');


header("Content-disposition: attachment; filename=".$object->file['filename']);
//header('Content-name: '.$object->file['filename']);
  header('Content-Type:application-x/force-download'); 
echo $object->getBytes();

核實。 這適用於小於 100MB 的文件。

閱讀文檔, http://php.net/manual/en/mongogridfsfile.getbytes.php

警告:這會將文件加載到內存中。 如果文件比你的內存大,這會導致問題!

所以你需要將大文件存儲在塊中,然后循環並回顯塊,我搜索了谷歌並找到了這個(3.展示了如何基於塊訪問文件):

http://blog.hardkap.com/index.php/posts/00069/MongoDB---GridFS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM