Search code examples
phpubuntucommand-linemv

How to change folder name to ubuntu root directory


I am trying to change folder name on Ubuntu root directory. It is working from terminal, but when I apply the same command in PHP, the name is not changed.

exec("mv old_name new_name");

I have also tried this:

exec("mv /old_name /new_name");

Solution

  • Use rename — Renames a file or directory

    <?php
    rename("/tmp/tmp_file.txt", "/home/user/login/docs/my_file.txt");
    ?>
    

    For more info refer this link: http://php.net/manual/en/function.rename.php