title: How to sync two folders in PHP?
body: <p>I am using windows, Mysql DB, PHP </p>
  
  <p>I am building the Joomla Component whose one of the functionality is to synchronize the folders
  I want to sync two folders of different name.. How can I do this? It has to be dne in the same machine, no two different servers are involved in it..</p>
  
  <p>How to sync two folders in PHP?</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>IN Context of Alex Reply</p>
  
  <p><strong>What if i am editing any .jpg file in one folder and saving it with same name as it has, also this file is already present in other folder. And I want this edited pic to be transfered to the other folder.?</strong> also I have Joomla's nested file structured to be compared</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I have a recursive function which will output me the complete structure of folder... if u can just use it to concat ur solution in... </p>
  
  <pre><code>&lt;?
  function getDirectory($path = '.', $ignore = '') {
      $dirTree = array ();
      $dirTreeTemp = array ();
      $ignore[] = '.';
      $ignore[] = '..';
  
      $dh = @opendir($path);
  
      while (false !== ($file = readdir($dh))) {
  
          if (!in_array($file, $ignore)) {
              if (!is_dir("$path/$file")) {
                  $stat = stat("$path/$file");
                  $statdir = stat("$path");
                  $dirTree["$path"][] = $file. " === ". date('Y-m-d H:i:s', $stat['mtime']) . " Directory == ".$path."===". date('Y-m-d H:i:s', $statdir['mtime']) ;
  
              } else {
  
                  $dirTreeTemp = getDirectory("$path/$file", $ignore);
                  if (is_array($dirTreeTemp))$dirTree = array_merge($dirTree, $dirTreeTemp);
              }
          }
      }
      closedir($dh);
  
      return $dirTree;
  }
  
  
  $ignore = array('.htaccess', 'error_log', 'cgi-bin', 'php.ini', '.ftpquota');
  
  $dirTree = getDirectory('.', $ignore);
  ?&gt;
  &lt;pre&gt;
      &lt;?
      print_r($dirTree);
      ?&gt;
  &lt;/pre&gt; 
  </code></pre>