Backend Development 3 min read

Using PHP rename() Function to Rename Files and Directories

The article explains PHP's rename() function, detailing its syntax, required $source and $target parameters, return values, and provides clear examples for renaming both files and directories, along with important permission considerations and a concise summary of its usage.

php中文网 Courses
php中文网 Courses
php中文网 Courses
Using PHP rename() Function to Rename Files and Directories

In PHP, the rename() function is used to rename files or directories by specifying the source name and the target name.

Syntax:

bool rename ( string $source , string $target )

Parameters:

$source : the name of the source file or directory (required).

$target : the name of the destination file or directory (required).

Return value: Returns TRUE on success and FALSE on failure.

Examples:

Renaming a file:

Renaming a directory:

Notes: The function may be limited by filesystem permissions; ensure you have sufficient rights. If the source does not exist, rename() returns FALSE .

Summary: The rename() function provides a simple way to change the name of files or directories in PHP, and the examples demonstrate its basic usage.

BackendPHPfilesystemfile handlingrename
php中文网 Courses
Written by

php中文网 Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.