Writing and Moving a PHP File with fopen and fwrite
Using php copy() and rename() functions are two such methods to copy and rename php files. However, fopen() and fwrite() functions can alos do the trick. The example below is a method regarding how to copy, move and rename a php file. In this case, the template file and the copied file with a new name exist in the root directory.
// Here we get the source file
$file = file_get_contents(‘page_template.php’, true);
//This makes a name like mysite.com/myurl.php
//opens or creates the file here with the desired name
$fh = fopen($mytitle, ‘w’);
//writes the file page_template.php to the new file name