Home > php教程 > php手册 > Rename更改文件、文件夹名称

Rename更改文件、文件夹名称

WBOY
Release: 2016-06-13 10:42:13
Original
1232 people have browsed it

rename()命令可以实现文件文件夹的更名操作,而且还可以实现文件、文件夹的移动操作,命令格式为:

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

  下面演示rename的具体应用:

文件位置如图:



 

目的:1.把cache.txt 更名为rename.txt;

           2.将cache2.txt更名为cache3.txt

           3.将html目录 更名为 cache

           4.将file目录转移到html目录下(可以实现更名)


代码实现(有错误):
   $file = "html/cache.txt";
  $rename = "html/rename.txt";
  if(rename($file,$rename)){
   echo "更名成功";
  }else{
   echo "更名失败";
  }
  rename("html/cache2","html/cache3.txt");
  rename("html","cache");
  rename("file","html/files");
 ?>

常见错误分析:
 

检查语法,无问题;经查file目录不存在,导致错误。更为files编译成功

这个错误小啊,致命啊…………………………

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template