Moving Files in PHP
The function rename also allows moving
files. To do this, the second parameter of the function
needs to specify the new path to the file. Let's
move our file to the dir folder as an example,
while renaming it to new.txt:
<?php
rename('test.txt', 'dir/new.txt');
?>
You can perform only the move without renaming the file itself:
<?php
rename('test.txt', 'dir/test.txt');
?>
Let there be a file file.txt in the root of your site.
Also, let there be a folder
dir in the root of your site. Move the file to this folder.
Let there be a folder dir1 in the root of your site,
and a file file.txt inside it. Also, let
there be a folder dir2 in the root of your site.
Move the file to this folder.