(PHP 4, PHP 5)
rename — 重命名一个文件或目录
$oldname
, string $newname
[, resource $context
] )
尝试把 oldname 重命名为
newname。
成功时返回 TRUE, 或者在失败时返回 FALSE.
Example #1 rename() 例子
<?php
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
?>
Note:
在 PHP 4.3.3 之前, rename() 不能在基于 *nix 的系统中跨磁盘分区重命名文件。
Note: 自 PHP 5.0.0 起 rename() 也可用于某些 URL 封装协议。参见Supported Protocols and Wrappers 的列表看看 rename() 支持哪些 URL 封装协议。
Note: 用于
oldname中的封装协议必须和用于newname中的相匹配。
Note: 在 PHP 5.0.0 中增加了 对上下文(Context)的支持。 有关 上下文(Context) 的说明参见 Streams。
参见 copy(), unlink() 和 move_uploaded_file()。
oldname
Note:
The old name. The wrapper used in
oldnamemust match the wrapper used innewname.
newname
The new name.
context
Note: 在 PHP 5.0.0 中增加了 对上下文(Context)的支持。 有关 上下文(Context) 的说明参见 Streams。
成功时返回 TRUE, 或者在失败时返回 FALSE.
| 版本 | 说明 |
|---|---|
| 5.3.1 | rename() can now rename files across drives in Windows. |
| 5.0.0 | rename() can now also be used with some URL wrappers. Refer to Supported Protocols and Wrappers for a listing of which wrappers support rename(). |
| 4.3.3 | rename() may now be able to rename files across partitions on *nix based systems, provided the appropriate permissions are held. 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 #2 Example with rename()
<?php
rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
?>