Home >Backend Development >PHP Tutorial >How to use the rename() function in php

How to use the rename() function in php

怪我咯
怪我咯Original
2017-07-06 10:28:011771browse

This article mainly introduces the usage of rename() function in php. It analyzes the meaning of parameters in the rename() function and the specific usage method in more detail. It has certain reference value and needs Friends can refer to

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, false is returned.

Statement: rename(oldname,

newname,context)

##Parameters##oldnameRequired, specifies the file or directory to be renamed.newnameRequired, specifies the new name of the file or directorycontextRequired, specifies the environment of the file handle, context is the modifiable stream 's set of optionsNote
Description
Behavior
: Prior to PHP 4.3.3, rename() could not be renamed across disk partitions on *nix-based systems. Name the file.

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.

The code is as follows:

<?php
rename("images","pictures");
?>

oldpath ---- the original path of the file or directory, $newpath ---- the new defined path, then rename($oldpath,$newpath) can be completed 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, so you can also use rename cleverly () function to complete the

delete

operation, for example:

$path ---- file or directory path

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

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

The above is the detailed content of How to use the rename() function in php. For more information, please follow other related articles on the PHP Chinese website!

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