(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() - 將上傳的文件移動到新位置