move a directory in php

To move a directory in PHP, you can use the rename() function. The rename() function can be used to rename or move a file or directory.

Here is an example code snippet that shows how to move a directory in PHP:

main.php
$oldDir = '/path/to/old/dir';
$newDir = '/path/to/new/dir';

if (!is_dir($oldDir)) {
    die('The old directory does not exist');
}

if (!rename($oldDir, $newDir)) {
    die('The directory could not be moved');
}

echo 'The directory was successfully moved to ' . $newDir;
273 chars
13 lines

In the above example, we first check if the old directory exists using the is_dir() function. If the old directory exists, we then use rename() function to move it to the new directory. Finally, we display a message to the user to confirm that the directory was moved successfully.

Note that the rename() function can also be used to rename a directory by providing a new name in place of the new directory path.

gistlibby LogSnag