MongoDB\GridFS\Bucket::openDownloadStream()
定义
参数
$id
:混合- 要下载的文件的
_id
。
Return Values
可读的流资源。
错误/异常
如果未找到符合选择条件的文件,则为MongoDB\GridFS\Exception\FileNotFoundException
。
MongoDB\ 驱动程序\Exception\RuntimeException 对于扩展级别的其他错误(例如连接错误)。
示例
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $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));
而输出将类似如下所示:
string(6) "foobar"