rename() function in PHP



The rename() function renames a file or directory. The function returns TRUE on success or FALSE on failure.

Syntax

rename(old_filename, new_filename, context)

Parameters

  • old_filename − The old name of the file or directory.

  • new_filename − The new name of the file or directory.

  • context − Specify the behaviour of the stream.

Return

The rename() function returns TRUE on success or FALSE on failure.

Example

<?php
   rename("one.txt","two.txt");
?>

Output

TRUE

Let us see another example.

Example

<?php
   rename("D:
ew\tutorials\java.docx","D:
ew\tutorials\programming\java.docx"); ?>

Output

TRUE
Samual Sam
Samual Sam

Learning faster. Every day.


Advertisements