How to use the rename() function in php

怪我咯
Release: 2023-03-12 20:48:02
Original
1730 people have browsed it

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");
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!