这里是普通文章模块栏目内容页
【转】ecshop 相册如何生成缩略图

现在的ecshop  中相册里面的图片没有生成相应的缩略图,如果图片太大就会把页面撑坏掉,下面是ecshop相册生成缩略图的方法:

..找到.\upload\admin\includes\lib_goods.php 这个文件,在295行这里的方法

/**
* 保存某商品的相册图片
* @param   int     $goods_id
* @param   array   $image_files
* @param   array   $image_descs
* @return  void
*/
function handle_gallery_image($goods_id, $image_files, $image_descs, $image_urls)
{
/* 是否处理缩略图 */
$proc_thumb = (isset($GLOBALS['shop_id']) && $GLOBALS['shop_id'] > 0)? false : true;
foreach ($image_descs AS $key => $img_desc)
{
/* 是否成功上传 */
$flag = false;
if (isset($image_files['error']))
{
if ($image_files['error'][$key] == 0)
{
$flag = true;
}
}
else
{
if ($image_files['tmp_name'][$key] != 'none')
{
$flag = true;
}
}

        if ($flag)
{
// 生成缩略图
if ($proc_thumb)
{
$thumb_url = $GLOBALS['image']->make_thumb($image_files['tmp_name'][$key], $GLOBALS['_CFG']['thumb_width'],  $GLOBALS['_CFG']['thumb_height']);
$thumb_url = is_string($thumb_url) ? $thumb_url : '';
}

            $upload = array(
'name' => $image_files['name'][$key],
'type' => $image_files['type'][$key],
'tmp_name' => $image_files['tmp_name'][$key],
'size' => $image_files['size'][$key],
);
if (isset($image_files['error']))
{
$upload['error'] = $image_files['error'][$key];
}
$img_original = $GLOBALS['image']->upload_image($upload);
if ($img_original === false)
{
sys_msg($GLOBALS['image']->error_msg(), 1, array(), false);
}
$img_url = $img_original;

            if (!$proc_thumb)
{
$thumb_url = $img_original;
}
// 如果服务器支持GD 则添加水印
if ($proc_thumb && gd_version() > 0)
{
$pos        = strpos(basename($img_original), '.');
$newname    = dirname($img_original) . '/' . $GLOBALS['image']->random_filename() . substr(basename($img_original), $pos);
copy('../' . $img_original, '../' . $newname);
$img_url    = $newname;

                $GLOBALS['image']->add_watermark('../'.$img_url,'',$GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']);
}

            




    //********************************************************
//                      生成商品图片的缩略图  开始 
//********************************************************
if ($GLOBALS['_CFG']['image_width'] != 0 || $GLOBALS['_CFG']['image_height'] != 0)
{

$goods_thumb_url = $GLOBALS['image']->make_thumb('../'. $img_url , $GLOBALS['_CFG']['image_width'],  $GLOBALS['_CFG']['image_height']);
if ($goods_thumb_url === false)
{
sys_msg($image->error_msg(), 1, array(), false);
}

// 加水印
if (intval($GLOBALS['_CFG']['watermark_place']) > 0 && !empty($GLOBALS['_CFG']['watermark']))
{
if ($image->add_watermark('../'.$goods_thumb_url,'',$GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']) === false)
{
sys_msg($image->error_msg(), 1, array(), false);
}
}
}

            
//********************************************************
//                     生成商品图片的缩略图    结束
//********************************************************

            
******  红色部分为新加内容*******








/* 重新格式化图片名称 */
$img_original = reformat_image_name('gallery', $goods_id, $img_original, 'source');
$img_url = reformat_image_name('gallery', $goods_id, $img_url, 'goods');
$thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb');


//********************************************************
$goods_thumb_url = reformat_image_name('gallery_thumb', $goods_id, $goods_thumb_url, 'goods');

             //********************************************************
            

$sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original,goods_img) " .
"VALUES ('$goods_id', '$img_url', '$img_desc', '$thumb_url', '$img_original','$goods_thumb_url')";

$GLOBALS['db']->query($sql);



/* 不保留商品原图的时候删除原图 */
if ($proc_thumb && !$GLOBALS['_CFG']['retain_original_img'] && !empty($img_original))
{
$GLOBALS['db']->query("UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET img_original='' WHERE `goods_id`='{$goods_id}'");
@unlink('../' . $img_original);
}
}
elseif (!empty($image_urls[$key]) && ($image_urls[$key] != $GLOBALS['_LANG']['img_file']) && ($image_urls[$key] != 'http://') && copy(trim($image_urls[$key]), ROOT_PATH . 'temp/' . basename($image_urls[$key])))
{
$image_url = trim($image_urls[$key]);

            //定义原图路径
$down_img = ROOT_PATH . 'temp/' . basename($image_url);

            // 生成缩略图
if ($proc_thumb)
{
$thumb_url = $GLOBALS['image']->make_thumb($down_img, $GLOBALS['_CFG']['thumb_width'],  $GLOBALS['_CFG']['thumb_height']);
$thumb_url = is_string($thumb_url) ? $thumb_url : '';
$thumb_url = reformat_image_name('gallery_thumb', $goods_id, $thumb_url, 'thumb');
}

            if (!$proc_thumb)
{
$thumb_url = htmlspecialchars($image_url);
}

            /* 重新格式化图片名称 */
$img_url = $img_original = htmlspecialchars($image_url);
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " .
"VALUES ('$goods_id', '$img_url', '$img_desc', '$thumb_url', '$img_original')";
$GLOBALS['db']->query($sql);

            @unlink($down_img);
}
}
}

goods_img  这个字段是我在  数据表 ecs_goods_gallery  表中添加的字段  用来存放 图片的商品缩略图的路径