title: PHP Copy all files/folders from one directory to another
body: <p>I'm trying to get a "reset" script working in PHP to essentially just copy all files/folders from one specific directory to another.</p>
  
  <p>I've found plenty of snippets of code on Stackoverflow for recursively copying files/folders but I cannot get any of them to work.</p>
  
  <p>My directory essentially looks like:</p>
  
  <pre><code>/public_html/folder1/reset.php
  /public_html/folder1/files/
  /public_html/docs/reset/files/
  </code></pre>
  
  <p>The <code>reset.php</code> file is the file I am trying to get working and I want to copy all of the files from <code>/docs/reset/files/</code> over to <code>/folder1/files/</code> overwriting everything...</p>
  
  <p>I've tried the following code but it generates a 500mb~ file full of errors</p>
  
  <pre><code>&lt;?php 
  function recurse_copy($src,$dst) { 
      $dir = opendir($src); 
      @mkdir($dst); 
      while(false !== ( $file = readdir($dir)) ) { 
          if (( $file != '.' ) &amp;&amp; ( $file != '..' )) { 
              if ( is_dir($src . '/' . $file) ) { 
                  recurse_copy($src . '/' . $file,$dst . '/' . $file); 
              } 
              else { 
                  copy($src . '/' . $file,$dst . '/' . $file); 
              } 
          } 
      } 
      closedir($dir); 
  }
  
  recurse_copy("../docs/reset/", "/")
  
  ?&gt;
  </code></pre>
  
  <p>The code does appear to be cycling through correctly but the paths are all wrong.</p>
  
  <p><code>[18-Jun-2020 07:54:33 UTC] PHP Warning:  copy(/files//files/copies/index.php): failed to open stream: No such file or directory in /home/USERNAME/public_html/folder1/reset.php on line 11</code></p>
  
  <p>If I could get the above working I was going to try the following:</p>
  
  <pre><code>$src = '/full/path/to/src'; // or relative path if so desired 
  $dst = '/full/path/to/dst'; // or relative path if so desired
  $command = 'cp -a ' . $src . ' ' .$dst;
  $shell_result_output = shell_exec(escapeshellcmd($command));
  </code></pre>
  
  <p>As I assume that would be faster?</p>
  
  <p>I must be doing something wrong and I'm sure it's going to be something really minor but I cannot figure out what I am doing wrong.</p>