rename

(PHP 3, PHP 4, PHP 5)

rename -- 更名一個檔案或目錄

說明

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

嘗試把 oldname 更名為 newname

若果成功則返回 TRUE,失敗則返回 FALSE

例子 1. rename() 例子

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

注: 在 PHP 4.3.3 之前,rename() 不能在基於 *nix 的系統中跨磁碟分區更名檔案。

注: 自 PHP 5.0.0 起 rename() 也可用於某些 URL 封裝協定。參見附錄 M 的清單看看 rename() 支援哪些 URL 封裝協定。

注: 用於 oldname 中的封裝協定必須和用於 newname 中的相符合。

注: 對 context 的支援是 PHP 5.0.0 增加的。有關 context 的說明見參考 CXLV, Stream Functions

參見 copy()unlink()move_uploaded_file()