code: protected function safeCopy($source, $target)
      {
          $source = fopen($source, 'r');
          $target = fopen($target, 'w+');
  
          stream_copy_to_stream($source, $target);
          fclose($source);
          fclose($target);
      }
docs: Copy file using stream_copy_to_stream to work around https://bugs.php.net/bug.php?id=6463
  
  @param string $source
  @param string $target