Home  >  Article  >  Backend Development  >  The wonderful use of the rename() function in php_PHP tutorial

The wonderful use of the rename() function in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:42675browse

​ As we all know, the rename() function can rename files or directories. In fact, it can do a lot of things.
Friends who are familiar with Unix should know the shell command mv, which is equivalent to win32 movement, and can be renamed while moving. I found that php's rename() function is equivalent to mv. It not only has a simple renaming function, but can also change the path of files or even entire directories.
For example:
$oldpath ----The original path of the file or directory
$newpath ----New definition path
Then rename($oldpath,$newpath) can complete the file/directory moving operation
After my testing, both win32 and unix php4 versions support this function.
In addition, it seems that the win32 version of php4 has canceled the unlink() function. Then 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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445593.htmlTechArticleAs we all know, the rename() function can rename files or directories. In fact, it can do a lot of things. Friends who are familiar with Unix should know the shell command mv, which is quite similar to wi...
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