Get the App
SLTechnology News&Howtos  ›  Development  › 

How php modifies the name of a file

Shulou Source: shulou.com Published: 2022-06-03 13:51:28 09月27日 Update

Editor to share with you php how to modify the name of the file, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

In php, you can use the rename () function to change the name of a file, which renames a file or directory with the syntax "rename (the name of the file to be modified, the new file name)"; returns TRUE if the modification is successful, or FALSE if the modification fails.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use the rename () function to change the name of the file.

Example: there is a text file named "test.txt"

Now if we want to change it to "newtest.txt", we can use the following code:

Output result:

Open the folder and look at the files:

OK modified successfully! Let's take a brief look at the rename () function:

The rename () function can rename a file or directory, returning TRUE on success and FALSE on failure. The syntax format of this function is as follows:

Rename (string $oldname, string $newname [, resource $context])

Where $oldname is the file name to be modified, $newname is the new file name, and $context is the optional parameter that specifies the environment of the file handle. Context is a set of options that can modify the behavior of the flow.

There are several points to note when using the rename () function:

For non-empty folders, you can only move under the same drive character

For empty folders, rename () can be moved between different drive letters. But the parent directory of the destination folder must exist

For files, rename () can also move between different drive letters.

The above is all the contents of the article "how to modify the name of a file by php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: File function name file name folder success directory article move different content environment syntax not much between code parameters handles can make most of Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology Shulou Tech Info Redmi MariaDB