Home  >  Article  >  Backend Development  >  Analysis of the usage of rename function in php, usage of phprename function_PHP tutorial

Analysis of the usage of rename function in php, usage of phprename function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:00823browse

Analysis of usage of rename function in php, usage of phprename function

This article analyzes the usage of the rename() function in PHP with examples. Share it with everyone for your reference. The details are as follows:

php filesystem function, rename() function renames a file or directory. If successful, the function returns true. If it fails, return false.

Statement:rename(oldname,newname,context)

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

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 the one used in newname.

Note: Support for context was added in php 5.0.0.

Copy code The code is as follows:
rename("images","pictures");
?>

oldpath ---- the original path of the file or directory, $newpath ---- the new defined path, then rename($oldpath,$newpath) can complete the file/directory moving operation. After my testing, win32 and All php4 versions of unix support this function.

In addition, it seems that the win32 version of php4 has canceled the unlink() function, so you can also use the rename() function to complete the deletion operation, for example:

$path ---- file or directory path

$tmp ---- tmp directory (/tmp)

Use rename($path,$tmp) to move the file to the tmp directory.

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912280.htmlTechArticleAnalysis of the usage of the rename function in php, usage of the phprename function. This article analyzes the usage of the rename() function in php. Share it with everyone for your reference. The details are as follows: php filesystem function, rena...
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