In this tutorial, We will learn how to change the file name inside a folder in PHP.


Example:

<?php
  
/* Existing File name */
$filePath = 'images/test.jpeg';
  
/* New File name */
$newFileName = 'images/test_new.jpeg';
  
/* Rename File name */
if( !rename($filePath, $newFileName) ) {  
    echo "File can't be renamed!";  
}  
else {  
    echo "File has been renamed!";  
} 
  
?>

Thanks, I hope it will help you........