Definition
Parameters
$id: mixed- The
_idof the file to download.
Return Values
A readable stream resource.
Errors/Exceptions
MongoDB\GridFS\Exception\FileNotFoundException if no file was found for the selection criteria.
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
Examples
$bucket = (new MongoDB\Client)->test->getGridFSBucket();
$uploadStream = fopen('php://temp', 'w+b');fwrite($uploadStream, "foobar");rewind($uploadStream);
$id = $bucket->uploadFromStream('filename', $uploadStream);
$downloadStream = $bucket->openDownloadStream($id);
var_dump(stream_get_contents($downloadStream));The output would then resemble:
string(6) "foobar"