$filecontent="Code For File To Insert"; mkdir('/home/path/public_html/'.$username, 0777); if ($fp = fopen("/home/path/public_html/".$username."/index.php", "w")) { fwrite($fp, $filecontent); chmod("/home/path/public_html/".$username."/index.php", 0755); fclose($fp); }