Home >Backend Development >PHP Tutorial >rename() function in php_PHP tutorial

rename() function in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:01:491175browse

php tutorial rename() function

php filesystem function

Definition and usage

rename() function renames a file or directory.

If successful, the function returns true. On failure, returns false.

Grammar

rename(oldname,newname,context)
参数 描述
oldname 必需。规定要重命名的文件或目录。
newname 必需。规定文件或目录的新名称。
context 必需。规定文件句柄的环境。context 是可修改流的行为的一套选项。

Tips and Notes

Note: Prior to php 4.3.3, rename() could not rename files across disk partitions on *nix-based systems.

Note: The encapsulation protocol used in oldname must match that used in newname.

Note: Support for context was added in php 5.0.0.

Example

<!--?phprename("images","pictures");?-->
oldpath ----文件或目录原来路径
$newpath ----新定义路径
那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作
经过我的测试,win32和unix的php4版本都支持这个功能。
另外,好象php4的win32版取消了unlink()函数。那么还可以巧用rename()函数来完成删除的操作,例如:
$path ---- 文件或目录路径
$tmp ---- tmp目录(/tmp)
用rename($path,$tmp) 将文件移动到tmp目录.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445427.htmlTechArticlephp tutorial rename() function php filesystem function definition and usage rename() function renames a file or directory. If successful, the function returns true. On failure, returns false. Grammar...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn