예제 #1
0
 public static function _copy($source, $destination, $args, $depth = 0)
 {
     if ($depth > $args['max_depth']) {
         return true;
     }
     if (is_file($source)) {
         if (is_dir($destination) || preg_match('|/$|', $destination)) {
             $destination = preg_replace('|/+$|', '', $destination);
             $destination = "{$destination}/" . basename($source);
         }
         if (false === ITFileUtility::mkdir(dirname($destination), $args['folder_mode'])) {
             return false;
         }
         if (false === @copy($source, $destination)) {
             return false;
         }
         @chmod($destination, $args['file_mode']);
         return true;
     } else {
         if (is_dir($source) || preg_match('|/\\*$|', $source)) {
             if (preg_match('|/\\*$|', $source)) {
                 $source = preg_replace('|/\\*$|', '', $source);
             } else {
                 if (preg_match('|/$|', $destination)) {
                     $destination = $destination . basename($source);
                 }
             }
             $destination = preg_replace('|/$|', '', $destination);
             $files = array_diff(array_merge(glob($source . '/.*'), glob($source . '/*')), array($source . '/.', $source . '/..'));
             if (false === ITFileUtility::mkdir($destination, $args['folder_mode'])) {
                 return false;
             }
             $result = true;
             foreach ((array) $files as $file) {
                 if (false === ITFileUtility::_copy($file, "{$destination}/", $args, $depth + 1)) {
                     $result = false;
                 }
             }
             return $result;
         }
     }
     return false;
 }