Reputation: 3280
Suppose my server has 4GB of ram and i uploaded a file having size 5GB. How can i download that file using gridfs. Following site states that http://www.php.net/manual/en/mongogridfsfile.getbytes.php If your file is bigger than memory than its a problem but doesn't tells a solution for that.
Can anyone have any solution for this. i use this demo code to access a file.
<?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();
?>
Upvotes: 2
Views: 684
Reputation: 2104
As of version 1.3.0 of the PHP Driver you can access the GridFS Files as a PHP stream, using $MongoGridFSFile->getResource().
Using that method you can iteratively read the data and print it out, avoiding the memory limitation on your server.
Upvotes: 3
Reputation: 786
Upvotes: 1