文档菜单
文档首页
/ / /
PHP 库手册
/ /

MongoDB\GridFS\Bucket::rename()

在本页

  • 定义
  • 参数
  • 错误/异常
  • 示例
MongoDB\GridFS\Bucket::rename()

通过其 _id 选择 GridFS 文件并更改其 filename

function rename($id, string $newFilename): void
$id : 混合类型
要重命名的文件的 _id
$newFilename : 字符串
新的 filename 值。

MongoDB\GridFS\Exception\FileNotFoundException 如果未找到符合选择标准的文件。

MongoDB\Driver\Exception\RuntimeException 用于其他扩展级别的错误(例如连接错误)。

<?php
$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"

返回

registerGlobalStreamWrapperAlias()