Click here to Skip to main content
15,037,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please let me explain my problem theoratically first. I have a few website templates on the server and I have created subdomain of my website like abc.xyz.com using php code. I need to copy the template folder's all contents(files and folders) to my abc folder automatically once the subdomain has been created. Currently I am doing this manually like uploading the template folder's contents to abc using fileZilla FTP. How can I achieve it with coding in php.

Here is my php code which makes subdomain automatically:

PHP
<?php

function create_subdomain($subDomain,$cPanelUser,$cPanelPass,$rootDomain) {

//  $buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain;

$buildRequest = "/frontend/x3/subdomain/doadddomain.html?rootdomain=" . $rootDomain . "&domain=" . $subDomain . "&dir=public_html/" . $subDomain;

    $openSocket = fsockopen('localhost',2082);
    if(!$openSocket) {
        return "Socket error";
        exit();
    }

    $authString = $cPanelUser . ":" . $cPanelPass;
    $authPass = base64_encode($authString);
    $buildHeaders  = "GET " . $buildRequest ."\r\n";
    $buildHeaders .= "HTTP/1.0\r\n";
    $buildHeaders .= "Host:localhost\r\n";
    $buildHeaders .= "Authorization: Basic " . $authPass . "\r\n";
    $buildHeaders .= "\r\n";

    fputs($openSocket, $buildHeaders);
    while(!feof($openSocket)) {
    fgets($openSocket,128);
    }
    fclose($openSocket);

    $newDomain = "http://" . $subDomain . "." . $rootDomain . "/";

    return "Created subdomain $newDomain";


}
?>


this is the function and I am passing the necessary parameters.
Posted

1 solution

ok finally got the solution:

<?php

 $source="E:\\tststs1";
 $dest="F:\\tststs1";
 
 copyr($source,$dest);

function copyr($source, $dest) 
{ 
    // Simple copy for a file 
    if (is_file($source)) { 
        return copy($source, $dest); 
    } 
  
    // Make destination directory 
    if (!is_dir($dest)) { 
        mkdir($dest); 
    } 
  
    // Loop through the folder 
    $dir = dir($source); 
    while (false !== $entry = $dir->read()) { 
        // Skip pointers 
        if ($entry == '.' || $entry == '..') { 
            continue; 
        } 
  
        // Deep copy directories 
        if ($dest !== "$source/$entry") { 
            copyr("$source/$entry", "$dest/$entry"); 
        } 
    } 
  
    // Clean up 
    $dir->close(); 
    return true; 
} 

?>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900