MongoDB\GridFS\Bucket::rename()
定义
参数
$id
: 混合类型- 要重命名的文件的
_id
。 $newFilename
: 字符串- 新的
filename
值。
错误/异常
MongoDB\GridFS\Exception\FileNotFoundException
如果未找到符合选择标准的文件。
MongoDB\Driver\Exception\RuntimeException 用于其他扩展级别的错误(例如连接错误)。
示例
$bucket = (new MongoDB\Client)->test->selectGridFSBucket(); $stream = fopen('php://temp', 'w+b'); fwrite($stream, "foobar"); rewind($stream); $id = $bucket->uploadFromStream('a', $stream); $bucket->rename($id, 'b'); var_dump(stream_get_contents($bucket->openDownloadStreamByName('b')));
输出结果如下
string(6) "foobar"