You are viewing an offline version of MongoDB documentation. Some page features might be unavailable. To view the latest version of the page or use interactive features, visit the live page.
MongoDB\GridFS\Bucket::openDownloadStreamByName()
Definition
Parameters
$filename: string- The
filenameof the file to download. $options: arrayAn array specifying the desired options.
NameTypeDescriptionrevision
integer
The revision of the file to retrieve. Files with the same
filenamewill be differentiated by theiruploadDatefield.Revision numbers are defined as follows:
0 = the original stored file
1 = the first revision
2 = the second revision
etc...
-2 = the second most recent revision
-1 = the most recent revision
Defaults to -1 (i.e. the most recent revision).
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->selectGridFSBucket(); $stream = fopen('php://temp', 'w+b'); fwrite($stream, "foobar"); rewind($stream); $bucket->uploadFromStream('filename', $stream); var_dump(stream_get_contents($bucket->openDownloadStreamByName('filename')));
The output would then resemble:
string(6) "foobar"