Rename function usage analysis _php techniques in PHP

Source: Internet
Author: User
Tags win32

This article analyzes the usage of rename () function in PHP. Share to everyone for your reference. Specifically as follows:

PHP filesystem function, rename () function renames a file or directory, and if successful, the function returns True. Returns False if the failure occurs.

Statement: rename (oldname,newname,context)

Parameters Describe
Oldname Required, specify the file or directory to be renamed.
NewName Required, specify a new name for the file or directory
Context Required, setting the context of a file handle, a set of options for modifying the behavior of a stream

Note: Before PHP 4.3.3, rename () cannot rename a file across a disk partition on a *nix based system.

Note: The encapsulation protocols used in oldname must match those used in newname.

Note: The support for the context is added by PHP 5.0.0.

Copy Code code as follows:
<?php
Rename ("Images", "pictures");
?>

OldPath----file or directory original path, $newpath----New definition path, then rename ($oldpath, $newpath) can complete file/directory move operation, after my test, This feature is supported by both Win32 and UNIX PHP4 versions.

In addition, as if the Win32 version of PHP4 cancels the unlink () function, you can also use the rename () function to complete the deletion, for example:

$path----file or directory path

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

Move the file to the TMP directory with rename ($path, $tmp).

I hope this article will help you with your PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.