Home >Backend Development >PHP Tutorial >php Rename 更改文件、文件夹名称_PHP

php Rename 更改文件、文件夹名称_PHP

WBOY
WBOYOriginal
2016-06-01 12:16:521286browse

命令格式为:
bool rename ( string oldname, string newname [, resource context] )
  下面演示rename的具体应用:
文件位置如图:
php Rename 更改文件、文件夹名称_PHP
目的: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");
?>

常见错误分析:
php Rename 更改文件、文件夹名称_PHP
检查语法,无问题;经查file目录不存在,导致错误。更为files编译成功

这个错误小啊,致命啊

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