Пример #1
0
function process_image_directory($dir, $query, $debug = false)
{
    global $config;
    global $db, $db_prefix, $user;
    global $resolutions_available;
    global $formats_available;
    global $formats_suffix;
    global $imagemagick_identify;
    global $imagemagick_convert;
    global $file_binary, $zip_binary, $unzip_binary;
    $files = array();
    $remove = array();
    if (!read_recursive($dir, $files, $remove)) {
        echo "Error reading directory structure\n<br>\n";
    } else {
        if (!empty($dir)) {
            $offset = strlen($dir) + 1;
        } else {
            $offset = 0;
        }
        foreach ($files as $num => $val) {
            $files[$num] = substr($val, $offset);
        }
        foreach ($remove as $num => $val) {
            $remove[$num] = substr($val, $offset);
        }
        usort($remove, "cmp");
        if ($debug) {
            echo "Files: \n<br>\n<br>\n";
            foreach ($files as $num => $val) {
                echo "[" . $num . "]: " . $val . "\n<br>\n";
            }
            echo "Remove: \n<br>\n<br>\n";
            foreach ($remove as $num => $val) {
                echo "[" . $num . "]: " . $val . "\n<br>\n";
            }
        }
        echo "Reading directory structure done.\n<br>\n<br>\n";
        foreach ($files as $file) {
            echo "<em>Reading file: " . $file . "</em>\n<br>\n";
            if (!empty($dir)) {
                $filename = $dir . addslashes(DIRECTORY_SEPARATOR . $file);
            } else {
                $filename = $file;
            }
            if (is_file($filename)) {
                $mimetype = '';
                $fileext = '';
                $dotpos = strrpos($filename, '.');
                if (strlen($filename) - $dotpos > 3 && strlen($filename) - $dotpos < 6) {
                    $fileext = strtolower(substr($filename, $dotpos + 1));
                }
                $ret = read_mime($filename, $mimetype, $fileext);
                if (!$ret) {
                    $errorstring = "Error reading image mimetype! \n<br>\n";
                    $errorstring .= "File:" . $filename . "\n<br>\n";
                    echo $errorstring;
                } else {
                    echo "Mimetype: " . $mimetype . "\n<br>\n";
                    if (in_array($mimetype, $formats_available)) {
                        // extract image information
                        // we already have the mimetype
                        $img_data = array();
                        $img_data['mime'] = $mimetype;
                        // try to read the rest
                        $ret = read_image($filename, $img_data);
                        if (!$ret) {
                            $errorstring = "Error reading image information! \n<br>\n";
                            $errorstring .= "File:" . $filename . "\n<br>\n";
                            echo $errorstring;
                        } else {
                            echo "Type:\t\t" . $img_data["type"] . "\n<br>\n";
                            echo "Width:\t\t" . $img_data["width"] . "\n<br>\n";
                            echo "Height:\t\t" . $img_data["height"] . "\n<br>\n";
                            // get output directory
                            $baseid = $query['baseid'];
                            $sql = "SELECT base FROM " . $db_prefix . "img_base WHERE img_baseid=" . $db->qstr($baseid);
                            $output_dir = $db->GetOne($sql);
                            if (empty($output_dir)) {
                                $errorstring = "Error reading output directory! \n<br>\n";
                                $errorstring .= "BaseID: " . $baseid . "\n<br>\n";
                                $errorstring .= "Directory: " . $output_dir . "\n<br>\n";
                                die($errorstring);
                            }
                            // use a temporary directory, where we can store the converted files until we have
                            // completed the task for all resolutions.
                            // we will move files from there into the correct directory later
                            $tmpdir = $config['imageTmp'];
                            if (!is_dir($tmpdir)) {
                                $errorstring = "Could not find temporary directory! \n<br>\n";
                                $errorstring .= "Path: " . $tmpdir . "\n<br>\n";
                                die($errorstring);
                            }
                            // check if we already have a cache directory structure, otherwise create
                            $ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, true, true, 0755);
                            if (!$ret) {
                                $errorstring = "Temporary directory cache does not exist or is not writable! \n<br>\n";
                                die($errorstring);
                            }
                            // generate image in all necessary resolutions
                            // you can skip resolutions by changing the array at this point
                            $resolutions = $resolutions_available;
                            foreach ($resolutions as $res) {
                                $ret = check_dir($tmpdir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                if (!$ret) {
                                    $errorstring = "Error creating temporary directory cache for resolution: {$res}! \n<br>\n";
                                    die($errorstring);
                                }
                            }
                            // generate temporary id string
                            $tmpid = generate_random_string();
                            // carry out conversion steps
                            echo "\n<br>\n<em>Generating image versions for all resolutions:</em>\n<br><br>\n";
                            if ($config['imagick_mode'] == 'fast') {
                                $ret = convert_image_batch($filename, $tmpdir . 'cache', $tmpid, $resolutions);
                                if ($ret) {
                                    echo "Generating images (batch mode)\t\t\t: success\n<br>\n";
                                    $convert_success = true;
                                } else {
                                    echo "Generating images (batch mode)\t\t\t: failed\n<br>\n";
                                    echo "Aborting...\n<br>\n";
                                    $convert_success = false;
                                }
                            } else {
                                // convert image to JPG at 1600x1200 as a base for the following conversion
                                $baseimage_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                $res = '1600x1200';
                                $ret = convert_image($filename, $baseimage_filename, $res, false);
                                if ($ret) {
                                    echo "Generating base image\t\t\t: success\n<br>\n";
                                    $convert_success = true;
                                } else {
                                    echo "Generating base image\t\t\t: failed\n<br>\n";
                                    echo "Aborting...\n<br>\n";
                                    $convert_success = false;
                                }
                                // the following lines will generate a JPG-version of your original image
                                // uncomment them, if you need it (requires additional computation time)
                                /*
                                if ($convert_success)
                                {
                                	$output_filename = $tmpdir.'cache'.DIRECTORY_SEPARATOR.$tmpid.'.jpg';
                                	
                                	$res = $img_data['width'].'x'.$img_data['height'];
                                	
                                	$ret = convert_image($filename,$output_filename,$res, false);
                                	
                                	if ($ret)
                                	{
                                		echo ("Writing (".$res.")\t\t\t: success\n<br>\n");
                                		$convert_success = true;
                                	}
                                	else
                                	{
                                		echo ("Writing (".$res.")\t\t\t: failed\n<br>\n");
                                		echo ("Aborting...\n<br>\n");
                                		$convert_success = false;
                                	}
                                }
                                */
                                if ($convert_success) {
                                    foreach ($resolutions as $res) {
                                        $ret = check_dir($tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                        // check if cache subdirectories exist
                                        if (!$ret) {
                                            $errorstring = "Error creating directory for resolution " . $res . "\n<br>\n";
                                            $errorstring .= "or directory exists and is not writable\n<br>\n";
                                            die($errorstring);
                                        }
                                        if ($res == '120x90') {
                                            $is_thumbnail = true;
                                        } else {
                                            $is_thumbnail = false;
                                        }
                                        $output_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                        $ret = convert_image($baseimage_filename, $output_filename, $res, $is_thumbnail);
                                        if ($ret) {
                                            echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
                                            $convert_success = true;
                                        } else {
                                            echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
                                            echo "Aborting...\n<br>\n";
                                            $convert_success = false;
                                            break;
                                        }
                                    }
                                }
                            }
                            if ($convert_success) {
                                // we have all necessary files now, so we get a correct id and move the files
                                //
                                // in unlikely cases this section will cause trouble, i.e. when someone gets
                                // a new id while we are copying and before we insert into the database
                                echo "\n<br>\n<em>Copying generated image versions to their correct locations:</em> \n<br><br>\n";
                                // check if we already have a cache directory structure, otherwise create
                                $ret = check_dir($output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR, true, true, 0755);
                                if (!$ret) {
                                    $errorstring = "Output directory cache does not exist or is not writable! \n<br>\n";
                                    die($errorstring);
                                }
                                // get new id for filename
                                $sql = "SELECT max(imageid)+1 FROM " . $db_prefix . "img";
                                $newid = $db->GetOne($sql);
                                if (!$newid) {
                                    $newid = 1;
                                }
                                // iterate through all available resolutions and check whether the target directory exists
                                // if yes, move the corresponding file, otherwise abort.
                                foreach ($resolutions as $res) {
                                    $ret = check_dir($output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res, true, true, 0755);
                                    // check if cache subdirectories exist
                                    if (!$ret) {
                                        $errorstring = "Error creating directory for resolution " . $res . "\n<br>\n";
                                        $errorstring .= "or directory exists and is not writable\n<br>\n";
                                        die($errorstring);
                                    }
                                    $tmp_filename = $tmpdir . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $tmpid . '.jpg';
                                    $output_filename = $output_dir . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $res . DIRECTORY_SEPARATOR . $query['collectionid'] . '-' . $newid . '.jpg';
                                    $ret = @copy($tmp_filename, $output_filename);
                                    if ($ret) {
                                        echo "Writing (" . $res . ")\t\t\t: success\n<br>\n";
                                        $convert_success = true;
                                    } else {
                                        echo "Writing (" . $res . ")\t\t\t: failed\n<br>\n";
                                        echo "Aborting...\n<br>\n";
                                        $convert_success = false;
                                        break;
                                    }
                                    // if unlink fails, we just loose some disk space
                                    @unlink($tmp_filename);
                                }
                                // if you decided to enable JPG-Versions in original resolution,
                                // uncomment the following lines to copy them to the target
                                // directory
                                /*
                                // copy the JPEG version with original resolution
                                if ($convert_success)
                                {
                                	$tmp_filename = $tmpdir.'cache'.DIRECTORY_SEPARATOR.$tmpid.'.jpg';
                                											
                                	$output_filename = $output_dir.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.$query['collectionid'].'-'.$newid.'.jpg';
                                		
                                	$ret = @copy($tmp_filename,$output_filename);
                                	
                                	$res = $img_data['width'].'x'.$img_data['height'];
                                	
                                	if ($ret)
                                	{
                                		echo ("Writing (".$res.")\t\t\t: success\n<br>\n");
                                		$convert_success = true;
                                	}
                                	else
                                	{
                                		echo ("Writing (".$res.")\t\t\t: failed\n<br>\n");
                                		echo ("Aborting...\n<br>\n");
                                		$convert_success = false;
                                	}
                                	
                                	// if unlink fails, we just loose some disk space
                                	@unlink($tmp_filename);	
                                }			
                                */
                                if ($config['imagick_mode'] != 'fast') {
                                    // try to delete temprorary base image
                                    // if unlink fails, we just loose some disk space
                                    @unlink($baseimage_filename);
                                }
                                if ($convert_success) {
                                    // all generated versions copied, so we finally try the original
                                    $newfilename = $query['collectionid'] . '-' . $newid . '.' . $formats_suffix[$img_data["mime"]];
                                    $source = $filename;
                                    $dest = $output_dir . DIRECTORY_SEPARATOR . $newfilename;
                                    $ret = @copy($filename, $output_dir . DIRECTORY_SEPARATOR . $newfilename);
                                    if (!$ret) {
                                        echo "Copying original image\t: failed\n<br>\n";
                                        echo "Aborting...\n<br>\n";
                                    } else {
                                        echo "Copying original image\t: success\n<br>\n";
                                        // set permissions
                                        $ret = @chmod($output_dir . DIRECTORY_SEPARATOR . $newfilename, 0755);
                                        if (!$ret) {
                                            echo "Modyfing permissions\t: failed\n<br>\n";
                                        } else {
                                            echo "Modyfing permissions\t: success\n<br>\n";
                                        }
                                        $ret = @unlink($filename);
                                        if (!$ret) {
                                            echo "Removing uploaded file\t: failed\n<br>\n";
                                        } else {
                                            echo "Removing uploaded file\t: success\n<br>\n";
                                        }
                                        echo "\n<br>\n";
                                        // here our critical section ends, after the next command, the image counter
                                        // is increased by 1
                                        // get current time
                                        $sql = "SELECT NOW()";
                                        $time = $db->GetOne($sql);
                                        $ret = insert_img($query['collectionid'], $newid, $baseid, $file, $img_data, $time);
                                        if (!$ret) {
                                            echo "Inserting into database (image)\t\t\t: failed\n<br>\n";
                                            echo "Aborting...\n<br>\n";
                                        } else {
                                            echo "Inserting into database (image)\t\t\t: success\n<br>\n";
                                            $ret = insert_meta($query['collectionid'], $newid, $time, $user['login'], $query['type']);
                                            if (!$ret) {
                                                echo "Inserting into database (meta)\t\t\t: failed\n<br>\n";
                                                echo "Aborting...\n<br>\n";
                                            } else {
                                                echo "Inserting into database (meta)\t\t\t: success\n<br>\n";
                                                if (!empty($query['group1id'])) {
                                                    $ret = insert_img_group($query['group1id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group1)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group1)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                                if (!empty($query['group2id'])) {
                                                    $ret = insert_img_group($query['group2id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group2)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group2)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                                if (!empty($query['group3id'])) {
                                                    $ret = insert_img_group($query['group3id'], $query['collectionid'], $newid);
                                                    if (!$ret) {
                                                        // a failed group insertion is non-critical, so we continue
                                                        echo "Inserting into database (group3)\t\t\t: failed\n<br>\n";
                                                    } else {
                                                        echo "Inserting into database (group3)\t\t\t: success\n<br>\n";
                                                    }
                                                }
                                            }
                                            // end of actions - output a newline
                                            echo "\n<br>\n";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Image is processed completely
            echo "<em>" . $file . " done</em>\n<br><br>\n";
            flush();
        }
    }
    // after all images have been processed, we try to clean up the upload directory, so things do not get inserted twice
    foreach ($remove as $removethis) {
        if (!empty($dir)) {
            $removedir = $dir . DIRECTORY_SEPARATOR . $removethis;
        } else {
            $removedir = $removethis;
        }
        if ($debug) {
            echo "Purging possible thumbs.db file from: " . $removedir . "\n<br>\n";
        }
        $ret = @unlink($removedir . 'Thumbs.db');
        if ($debug) {
            echo "Now removing: " . $removedir . "\n<br>\n";
        }
        $ret = @rmdir($removedir);
        if (!$ret) {
            $errorstring = "Notice: " . $removedir . " could not be removed\n<br>\n";
            $errorstring .= "Insufficient permission or directory not empty\n<br>\n";
            echo $errorstring;
        }
    }
    if ($debug) {
        echo "Purging possible thumbs.db file from: " . $dir . "\n<br>\n";
    }
    $ret = @unlink($dir . 'Thumbs.db');
    if ($debug) {
        echo "Now removing: " . $dir . "\n<br>\n";
    }
    $ret = @rmdir($dir);
    if (!$ret) {
        $errorstring = "Notice: " . $dir . " could not be removed\n<br>\n";
        $errorstring .= "Insufficient permission or directory not empty\n<br>\n";
        echo $errorstring;
    }
    return;
}
Пример #2
0
     echo "Modyfing permissions\t: failed\n<br>\n";
 } else {
     echo "Modyfing permissions\t: success\n<br>\n";
 }
 // here our critical section ends, after the next command, the image counter
 // is increased by 1
 // get current time
 $sql = "SELECT NOW()";
 $time = $db->GetOne($sql);
 $ret = insert_img($query['collectionid'], $newid, $baseid, $userfilename, $img_data, $time);
 if (!$ret) {
     echo "Inserting into database (image)\t\t\t: failed\n<br>\n";
     echo "Aborting...\n<br>\n";
 } else {
     echo "Inserting into database (image)\t\t\t: success\n<br>\n";
     $ret = insert_meta($query['collectionid'], $newid, $time, $user['login']);
     if (!$ret) {
         echo "Inserting into database (meta)\t\t\t: failed\n<br>\n";
         echo "Aborting...\n<br>\n";
     } else {
         echo "Inserting into database (meta)\t\t\t: success\n<br>\n";
         if (!empty($query['group1id'])) {
             $ret = insert_img_group($query['group1id'], $query['collectionid'], $newid);
             if (!$ret) {
                 // a failed group insertion is non-critical, so we continue
                 echo "Inserting into database (group1)\t\t\t: failed\n<br>\n";
             } else {
                 echo "Inserting into database (group1)\t\t\t: success\n<br>\n";
             }
         }
         if (!empty($query['group2id'])) {
Пример #3
0
 $DB->query("INSERT INTO {$db_prefix}articles (uid, title, content, dateline) VALUES ('{$sax_uid}', '{$title}', '{$content} <br /><br /><span style=\"font-weight:bold;color:#4685C4;background-color:#E9F1F8;\">自 WAP 发表</span>', '{$timestamp}')");
 $articleid = $DB->insert_id();
 // 关联文章分类
 foreach ($mids as $mid) {
     $DB->unbuffered_query("UPDATE {$db_prefix}metas SET count=count+1 WHERE mid='{$mid}' AND type='category'");
     $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '{$mid}')");
 }
 // 插入/更新Tags
 if ($keywords) {
     $tagdb = explode(',', $keywords);
     foreach ($tagdb as $tag) {
         if ($tag) {
             $tag = sax_addslashes($tag);
             $r = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE name='{$tag}' AND type='tag' LIMIT 1");
             if (!$r) {
                 $new_mid = insert_meta($tag, $slug, 'tag', 1);
                 $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '{$new_mid}')");
                 $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET tag_count=tag_count+1");
             } else {
                 $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '" . $r['mid'] . "')");
                 $DB->unbuffered_query("UPDATE {$db_prefix}metas SET count=count+1 WHERE mid='" . $r['mid'] . "' AND type='tag'");
             }
         }
     }
 }
 $DB->unbuffered_query("UPDATE {$db_prefix}users SET articles=articles+1 WHERE userid='{$sax_uid}'");
 $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET article_count=article_count+1");
 archives_recache();
 categories_recache();
 statistics_recache();
 newarticles_recache();
Пример #4
0
 if ($keywords != $oldtags) {
     $dostat = 1;
     $arrtag = explode(',', $keywords);
     $arrold = explode(',', $oldtags);
     $arrtag_num = count($arrtag);
     $arrold_num = count($arrold);
     for ($i = 0; $i < $arrtag_num; $i++) {
         if (!in_array($arrtag[$i], $arrold)) {
             $arrtag[$i] = trim($arrtag[$i]);
             if ($arrtag[$i]) {
                 $tag = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE name='{$arrtag[$i]}' AND type='tag' LIMIT 1");
                 if (!$tag['mid']) {
                     if (!$article['visible'] && $visible || $article['visible'] && $visible) {
                         $new_mid = insert_meta($arrtag[$i], $slug, 'tag', 1);
                     } elseif ($article['visible'] && !$visible || !$article['visible'] && !$visible) {
                         $new_mid = insert_meta($arrtag[$i], $slug, 'tag');
                     }
                     $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '{$new_mid}')");
                     $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET tag_count=tag_count+1");
                 } else {
                     $r = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}relationships WHERE cid='{$articleid}' AND mid='" . $tag['mid'] . "'");
                     if (!$r['mid']) {
                         $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '" . $tag['mid'] . "')");
                     }
                 }
             }
         }
     }
     for ($i = 0; $i < $arrold_num; $i++) {
         if ($arrold[$i] && !in_array($arrold[$i], $arrtag)) {
             $tag = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE name='{$arrold[$i]}' AND type='tag' LIMIT 1");
function insert_tag_in_article($name, $articleid = 0, $slug = '')
{
    global $DB, $db_prefix;
    $name = sax_addslashes($name);
    $r = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE name='{$name}' AND type='tag' LIMIT 1");
    if (!$r) {
        $new_mid = insert_meta($name, $slug, 'tag', 1);
        $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '{$new_mid}')");
        $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET tag_count=tag_count+1");
    } else {
        $DB->query("INSERT INTO {$db_prefix}relationships (cid, mid) VALUES ('{$articleid}', '" . $r['mid'] . "')");
        $DB->unbuffered_query("UPDATE {$db_prefix}metas SET count=count+1 WHERE mid='{$mid}' AND type='tag'");
    }
}
Пример #6
0
            $new_url = char_cv($new_url);
            if ($action == 'add') {
                $r = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE type='{$type}' AND slug='{$new_url}' LIMIT 1");
            } else {
                $r = $DB->fetch_one_array("SELECT mid FROM {$db_prefix}metas WHERE type='{$type}' AND slug='{$new_url}' AND mid!='{$mid}' LIMIT 1");
            }
            if ($r) {
                $location = getlink('category', $goaction, array('message' => 5));
            }
        }
    } else {
        $new_url = $new_name;
    }
    if (!$location) {
        if ($action == 'add') {
            insert_meta($new_name, $new_url, $type);
            if ($type == 'tag') {
                $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET tag_count=tag_count+1");
            }
            $location = getlink('category', $goaction, array('message' => 6));
        } else {
            $DB->unbuffered_query("UPDATE {$db_prefix}metas SET name='{$new_name}',slug='{$new_url}' WHERE mid='{$mid}' AND type='{$type}'");
            $location = getlink('category', $goaction, array('message' => 7));
        }
        categories_recache();
        statistics_recache();
        $new_url = $new_name = '';
    }
    header("Location: {$location}");
    exit;
}
Пример #7
0
 $old_db->SetFetchMode(ADODB_FETCH_ASSOC);
 $sql = "SELECT smg.sammlungid as sammlungid, smg.tabelle as tabelle, imb.base as base, imb.img_baseid AS baseid " . "FROM sammlung AS smg LEFT JOIN img_base imb ON smg.sammlungid = imb.sammlungid " . "WHERE imb.img_baseid = " . $old_db->qstr($_REQUEST['old_baseid']);
 $rs = @$old_db->Execute($sql);
 $old_table = $rs->fields['tabelle'];
 $old_img_dir = $rs->fields['base'];
 $sql2 = "SELECT " . $old_table . ".*," . $old_table . "_bild.bildid FROM " . $old_table . "," . $old_table . "_bild WHERE " . $old_table . ".bildnr = " . $old_table . "_bild.bildnr";
 // echo "$sql2\n";
 $rs2 = $old_db->Execute($sql2);
 $ng_db = NewADOConnection("mysql");
 $ng_res = $ng_db->NConnect($ng_hostname, $ng_username, $ng_password, $ng_name);
 $ng_db->SetFetchMode(ADODB_FETCH_ASSOC);
 $sql3 = "SELECT col.collectionid AS collectionid, col.name AS name, col.sammlung_ort AS sammlung_ort, imb.base AS base, imb.img_baseid AS baseid " . "FROM " . $ng_prefix . "collection AS col " . "LEFT JOIN " . $ng_prefix . "img_base AS imb ON col.collectionid = imb.collectionid " . "WHERE imb.img_baseid = " . $ng_db->qstr($_REQUEST['ng_baseid']);
 $rs3 = @$ng_db->Execute($sql3);
 $new_img_dir = $rs3->fields['base'];
 while (!$rs2->EOF) {
     insert_meta($_REQUEST['old_collection'], $_REQUEST['ng_baseid'], $rs2->fields, $old_db, $ng_db, $ng_prefix);
     $rs2->MoveNext();
 }
 $sql = "SELECT DISTINCT name1 FROM {$ng_prefix}meta WHERE" . " collectionid = " . $ng_db->qstr($_REQUEST['ng_collection']) . " AND name1 != ''";
 $rs = $ng_db->Execute($sql);
 while (!$rs->EOF) {
     $name = $ng_db->qstr(stripslashes($rs->fields['name1']));
     $artistnames = explode(',', $name);
     if (isset($artistnames[0])) {
         if (strlen($artistnames[0])) {
             $art_name = trim(stripslashes($artistnames[0]));
         }
     } else {
         $art_name = '';
     }
     if (isset($artistnames[1])) {