Duplicate folder with PHP
<p>I've been searching all morning for this.</p>

<p>Is there a simple PHP function that will duplicate a folder on my server, changing permissions temporarily along the way if needs be? Basically a PHP alternative to me using FTP to copy an entire folder down and then back up again?</p>

<p>I've tried the function below that I found online, but it does nothing I think probably due to permissions. I have tried it with <code>error_reporting(E_ALL);</code> and also checked the return value of each <code>copy()</code>, they all return false.</p>

<pre><code>copy_directory('/directory1','/directory2') 

function copy_directory($src,$dst) { 
    $dir = opendir($src); 
    @mkdir($dst); 
    while(false !== ( $file = readdir($dir)) ) { 
        if (( $file != '.' ) &amp;&amp; ( $file != '..' )) { 
            if ( is_dir($src . '/' . $file) ) { 
                copy_directory($src . '/' . $file,$dst . '/' . $file); 
            } 
            else { 
                copy($src . '/' . $file,$dst . '/' . $file); 
            } 
        } 
    } 
    closedir($dir); 
}  
</code></pre>
