function cp($src, $dest, $as_child = false, $exclude_regex = '', $include_hidden = false) { $src = fs :: clean_path($src); $dest = fs :: clean_path($dest); if (!is_dir($src)) { debug :: write_error('no such a directory', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('dir' => $src)); return false; } if(!fs :: mkdir($dest)) return false; $separator = fs :: separator(); if ($as_child) { $separator_regex = preg_quote($separator); if (preg_match( "#^.+{$separator_regex}([^{$separator_regex}]+)$#", $src, $matches)) { fs :: _do_mkdir($dest . $separator . $matches[1], 0777); $dest .= $separator . $matches[1]; } else return false;//??? } $items = fs :: find_subitems($src, 'df', $exclude_regex, false, $include_hidden); $total_items = $items; while (count($items) > 0) { $current_items = $items; $items = array(); foreach ($current_items as $item) { $full_path = $src . $separator . $item; if (is_file( $full_path)) copy($full_path, $dest . $separator . $item); elseif (is_dir( $full_path)) { fs :: _do_mkdir($dest . $separator . $item, 0777); $new_items = fs :: find_subitems($full_path, 'df', $exclude_regex, $item, $include_hidden); $items = array_merge($items, $new_items); $total_items = array_merge($total_items, $new_items); unset($new_items); } } } if($total_items) clearstatcache(); return $total_items; }