<?php
$BASEDIR="../temp/";
$destino="../temp2/";

function copyFile( $origem, $destino )
{
  $ret = true;
  $arrFile = array();
  $msg = "";
  if ( file_exists( $origem ) && is_dir( $origem ) )
  {
      if ($handle = opendir( $origem ))
      {
        while (false !== ($file = readdir($handle)))
        {
          if ( is_dir( $origem . $file ) )
          {
            if( $file != "." && $file != ".." )
            {
              echo "DIR  :::: ".$origem . $file."<br>\n";
              copyFile( $origem . $file."/", $destino. $file ."/" );
            }
          }else
          {
            copy( $origem . $file, $destino . $file );
            echo "&nbsp;&nbsp;&nbsp;&nbsp;file: ".$origem . $file."<br>\n";
          }// End if
        }// End while
        closedir($handle);
      }// End if()
  }else
  {
    $ret = false;
    echo "Erro";
  }// End if ( file_exists( $origem ) && is_dir( $origem ) )

  return( $ret );
}

function recursedir($BASEDIR)
{
  $hndl=opendir($BASEDIR);
  while($file=readdir($hndl))
  {
    if ($file=='.' || $file=='..')
      continue;
    $completepath="$BASEDIR/$file";
    if (is_dir($completepath))
    {
      # its a dir, recurse.
      recursedir($BASEDIR.'/'.$file);
      print "DIR  ::: $BASEDIR/$file<br>\n";
    }else
    {
      # its a file.
      print "file : $BASEDIR/$file<br>\n";
    }
  }
}

//recursedir($BASEDIR);
copyFile( $BASEDIR, $destino )
?>
