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

rename() function in php_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-20 11:01:49
Original
1179 people have browsed it

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

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...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template