Home >Backend Development >PHP Tutorial >php Rename Change file and folder names_PHP tutorial

php Rename Change file and folder names_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:101201browse

The command format is:
bool rename (string oldname, string newname [, resource context])
The following demonstrates the specific application of rename:
The file location is as shown in the figure:
php Rename Change file and folder names_PHP tutorial
Purpose: 1. Rename cache.txt to rename.txt;
2. Rename cache2.txt to cache3.txt
3. Rename the html directory to cache
4. Move the file directory to the html directory (Renaming can be achieved)
Code implementation (with errors):

Copy code The code is as follows:

$file = "html/cache.txt";
$rename = "html/rename.txt";
if(rename($file,$rename)){
echo "Rename Success";
}else{
echo "Rename failed";
}
rename("html/cache2","html/cache3.txt");
rename("html" ,"cache");
rename("file","html/files");
?>

Common error analysis:
php Rename Change file and folder names_PHP tutorial
Check the syntax and there is no problem; after checking, the file directory does not exist, causing an error. More files were compiled successfully

This error is small but fatal.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323488.htmlTechArticleThe command format is: bool rename (string oldname, string newname [, resource context]) The following demonstrates the specific application of rename : The file location is as shown in the figure: Purpose: 1. Rename cache.txt to re...
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
Previous article:PHPNext article:PHP