Search code examples
phpfilefile-rename

Rename PHP filename inside directory


I want to change filename in directory carbrands/alto/alto.php .Instead of alto.php I want to change as alto_new.php. But if I try to change name as

rename($old_name,$file_name);

After using this the filename changed but its not replace inside directory carbrands/alto instead its replaced out of directory. How to fix this issue?


Solution

  • You need to mention the entire path.

    $old_name = 'carbrands/alto/alto.php';
    $file_name = 'carbrands/alto/alto_new.php';
    rename($old_name,$file_name);