MongoDB\GridFS\Bucket::openDownloadStream()
定义
参数
$id
: mixed- 要下载的文件的
_id
。
返回值
可读的流资源。
错误/异常
MongoDB\GridFS\Exception\FileNotFoundException
如果未找到符合选择标准的文件。
MongoDB\Driver\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"