pTutorial

New way to learn Programming

How To Rename File In PHP

PHP rename function

PHP rename function is used to rename file or directory, return true in case of success and false in case of failure.

PHP rename function example

<?php
if(file_exists("uk.html")){
if(rename("resume.doc","resume.doc")){
  echo "File name has been changed";
}else{
echo "File name has not been changed";
}
}else{
  echo "File does not exist";
}	 

?>

Output

File name has been changed

Explanation

You can also use rename() function to rename directory also.

Note: If you execute this file again it will give the message "File does not exist"

See Also


QUOTES OF THE DAY

Knowledge without integrity is dangerous and dreadful.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER