php中rename函数用法分析_PHP

WBOY
Release: 2016-05-31 19:27:43
Original
968 people have browsed it

本文实例分析了php中rename()函数用法。分享给大家供大家参考。具体如下:

php filesystem 函数,rename() 函数重命名文件或目录,若成功,则该函数返回 true。若失败,则返回 false.

语句:rename(oldname,newname,context)

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

注释:在 php 4.3.3 之前,rename() 不能在基于 *nix 的系统中跨磁盘分区重命名文件.

注释:用于 oldname 中的封装协议必须和用于 newname 中的相匹配.

注释:对 context 的支持是 php 5.0.0 添加的.

代码如下:

rename("images","pictures");
?>

oldpath ----文件或目录原来路径,$newpath ----新定义路径,那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作,经过我的测试,win32和unix的php4版本都支持这个功能.

另外,好象php4的win32版取消了unlink()函数,那么还可以巧用rename()函数来完成删除的操作,例如:

$path ---- 文件或目录路径

$tmp ---- tmp目录(/tmp)

用rename($path,$tmp) 将文件移动到tmp目录.

希望本文所述对大家的PHP程序设计有所帮助。

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!