rename a directory in php

To rename a directory in PHP, we can use the rename() function. Here's an example:

main.php
$old_name = '/path/to/old/directory';
$new_name = '/path/to/new/directory';

if (rename($old_name, $new_name)) {
    echo "Directory renamed successfully.";
} else {
    echo "Error renaming directory.";
}
206 chars
9 lines

In this example, we pass the old directory path and the new directory path to the rename() function. If the function returns true, the directory was renamed successfully. If the function returns false, an error occurred and the directory was not renamed.

gistlibby LogSnag