导航首页 » 技术教程 » PHP:rename()的用法_Filesystem函数
PHP:rename()的用法_Filesystem函数 159 2023-12-15   

rename

(PHP 4, PHP 5)

rename — 重命名一个文件或目录

说明

bool rename ( string $oldname , string $newname [, resource $context ] )

尝试把 oldname 重命名为 newname

参数

oldname

Note:

用于 oldname 中的封装协议必须和用于 newname 中的相匹配。

newname

新的名字。

context

Note: 在 PHP 5.0.0 中增加了对上下文(Context)的支持。有关上下文(Context)的说明参见 Streams。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本 说明 5.3.1 可以在 Windows 上跨驱动器 rename() 文件。 5.0.0 rename() 也可用于某些 URL 封装协议。参见支持的协议和封装协议 的列表看看 rename() 支持哪些 URL 封装协议。 4.3.3 在有适当权限的时候 rename() 已经能够在基于 *nix 的系统中跨磁盘分区重命名文件。Warnings may be generated if the destination filesystem doesn't permit chown() or chmod() system calls to be made on files — for example, if the destination filesystem is a FAT filesystem.

范例

Example #1 rename() 例子

<?php
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
?>

参见

copy() - 拷贝文件 unlink() - 删除文件 move_uploaded_file() - 将上传的文件移动到新位置


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103