I need a way to populate this users subdomain/subdirectory with dynamic content specific to that use. I wrote a bit of code that just loops through another subdirectory, called template, and copies all the files from there into the users subdomain. This then leaves me with the issue of how I can make this newly copied static content dynamic. I've come up with one solution that opens the index.php file after copying it over and adds a $usrname = at the top.
Here is the code:
Code: Select all
<?
function copydir($source,$destination) {
if(!is_dir($destination)){
$oldumask = umask(0);
mkdir($destination, 01777); // so you get the sticky bit set
umask($oldumask);
}
$dir_handle = @opendir($source) or die("Unable to open");
while ($file = readdir($dir_handle)) {
if($file!="." && $file!=".." && !is_dir("$source/$file")){
copy("$source/$file","$destination/$file");
}
}
closedir($dir_handle);
}
if(!file_exists("../".$rowdata[storename]."/index.php")) {
copydir("../template","../".$rowdata[storename]);
copydir("../template/css","../".$rowdata[storename]."/css");
copydir("../template/css/images","../".$rowdata[storename]."/css/images");
$newFile = "../".$rowdata[storename]."/index.php";
$fh = fopen($newFile, 'c') or die("can't open file");
$data = '<? $usrname="'.$username.'" ?>';
fwrite($fh, $data);
fclose($fh);
header('location: template.php');
}
?>
This kind of leaves me in a bad place, since if the user ever wants to change their template, then I have to write a script that deletes the files from their subdirectory and the copies over the new ones from the different template. It just seems a little too much and not efficient to me at all, especially because there will be a small window where this user doesn't have any content on their site at all.
I'm interested in what others think of this or if these is a better way of achieving what I need.
Thanks.