function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
{
    global $convert, $phpbb_root_path, $config, $user, $db;
    $dirlist = $filelist = $bad_dirs = array();
    $src = path($src, $source_relative_path);
    $trg = path($trg);
    $src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__);
    $trg_path = $phpbb_root_path . $trg;
    if (!is_dir($trg_path)) {
        @mkdir($trg_path, 0777);
        @chmod($trg_path, 0777);
    }
    if (!phpbb_is_writable($trg_path)) {
        $bad_dirs[] = path($config['script_path']) . $trg;
    }
    if ($handle = @opendir($src_path)) {
        while ($entry = readdir($handle)) {
            if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') {
                continue;
            }
            if (is_dir($src_path . $entry)) {
                $dirlist[] = $entry;
            } else {
                $filelist[] = $entry;
            }
        }
        closedir($handle);
    } else {
        if ($dir = @dir($src_path)) {
            while ($entry = $dir->read()) {
                if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') {
                    continue;
                }
                if (is_dir($src_path . $entry)) {
                    $dirlist[] = $entry;
                } else {
                    $filelist[] = $entry;
                }
            }
            $dir->close();
        } else {
            $convert->p_master->error(sprintf($user->lang['CONV_ERROR_COULD_NOT_READ'], relative_base($src, $source_relative_path)), __LINE__, __FILE__);
        }
    }
    if ($copy_subdirs) {
        for ($i = 0; $i < sizeof($dirlist); ++$i) {
            $dir = $dirlist[$i];
            if ($dir == 'CVS') {
                continue;
            }
            if (!is_dir($trg_path . $dir)) {
                @mkdir($trg_path . $dir, 0777);
                @chmod($trg_path . $dir, 0777);
            }
            if (!phpbb_is_writable($trg_path . $dir)) {
                $bad_dirs[] = $trg . $dir;
                $bad_dirs[] = $trg_path . $dir;
            }
            if (!sizeof($bad_dirs)) {
                copy_dir($src . $dir, $trg . $dir, true, $overwrite, $die_on_failure, $source_relative_path);
            }
        }
    }
    if (sizeof($bad_dirs)) {
        $str = sizeof($bad_dirs) == 1 ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
        sort($bad_dirs);
        $convert->p_master->error(sprintf($str, implode('<br />', $bad_dirs)), __LINE__, __FILE__);
    }
    for ($i = 0; $i < sizeof($filelist); ++$i) {
        copy_file($src . $filelist[$i], $trg . $filelist[$i], $overwrite, $die_on_failure, $source_relative_path);
    }
}
function attach_thumb_height($attach_thumb_location)
{
    $relative_path = empty($convert->convertor['source_path_absolute']);
    $convert->convertor['garage_image_path'] = './garage/upload/';
    $src_path = relative_base(path($convert->convertor['garage_image_path'], $relative_path), $relative_path);
    if (file_exists($src_path . $attach_thumb_location)) {
        $attach_thumb_imagesize = @getimagesize($src_path . $attach_thumb_location);
        return $attach_thumb_imagesize[1];
    }
    return 0;
}