Index: branches/5.1.x/core/units/helpers/file_helper.php =================================================================== diff -u -N -r13962 -r14194 --- branches/5.1.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 13962) +++ branches/5.1.x/core/units/helpers/file_helper.php (.../file_helper.php) (revision 14194) @@ -1,6 +1,6 @@ CheckFolder($destination); + + if (!$result) { + // failed to create target directory + return false; + } + + while ( false !== ($file = readdir($dir)) ) { + if ($file == '.' || $file == '..') { + continue; + } + + if ( is_dir($source . DIRECTORY_SEPARATOR . $file) ) { + $result = $this->copyFolderRecursive($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + } + else { + $result = copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + } + + if (!$result) { + trigger_error('Cannot create file/directory "' . $destination . DIRECTORY_SEPARATOR . $file . '"', E_USER_WARNING); + break; + } + } + + closedir($dir); + + return $result; + } + + /** + * Copies all files from $source to $destination directory. Create destination directory, when missing. + * + * @param string $source + * @param string $destination + * @return bool + */ + function copyFolder($source, $destination) + { + if ( substr($source, -1) == DIRECTORY_SEPARATOR ) { + $source = substr($source, 0, -1); + $destination .= DIRECTORY_SEPARATOR . basename($source); + } + + $dir = opendir($source); + $result = $this->CheckFolder($destination); + + if (!$result) { + // failed to create target directory + return false; + } + + while ( false !== ($file = readdir($dir)) ) { + if ($file == '.' || $file == '..' || !is_file($source . DIRECTORY_SEPARATOR . $file)) { + continue; + } + + $result = copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + + if (!$result) { + trigger_error('Cannot create file "' . $destination . DIRECTORY_SEPARATOR . $file . '"', E_USER_WARNING); + break; + } + } + + closedir($dir); + + return $result; + } + + /** * Transforms given path to file into it's url, where each each component is encoded (excluding domain and protocol) * * @param string $url