Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

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.

 
<?php
// Here we get the source file
$file = file_get_contents(‘page_template.php’, true);
$ext=”.php”;
$url=”urlname”;
//This makes a name like mysite.com/myurl.php
$mytitle=$url.$ext;
//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
fwrite($fh, $file);
fclose($fh);?>