Index: units/helpers/file_helper.php =================================================================== --- units/helpers/file_helper.php (revision 14184) +++ units/helpers/file_helper.php (working copy) @@ -281,7 +281,49 @@ return $result; } + + /** + * Copies content a single file or folder recursively to specified destination + * @param string $source + * @param string $destination + * @param bool $recusive + * @return bool + */ + function Copy($source, $destination, $recursive = true) + { + static $in_recursion = false; + + $result = false; + if ( is_file($source) ) { + // 1. copy a single file + $result = copy($source, $destination); + if ( !$result ) { + trigger_error('Cannot create file "' . $destination . '"', E_USER_WARNING); + return false; + } + } + elseif ( is_dir($source) && ($recursive || (!$recursive && !$in_recursion)) ) { + // 2. read & copy folder content (recursively if required) + + $this->CheckFolder( $destination ); // check if folder exists + if ( !$recursive ) { + // set recursion status once processing 1st folder + $in_recursion = true; + } + + $handle = opendir($source); + while ( false !== ($file = readdir($handle)) ) { + // read through the folder and copy recurrsively + if ( $file != '.' && $file != '..' ) { + $result = $this->Copy( $source . '/' . $file, $destination . '/' . $file, $recursive); + } + } + closedir($handle); + } + return $result; + } + /** * Transforms given path to file into it's url, where each each component is encoded (excluding domain and protocol) *