/** * 保存某商品的相册图片 * @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_tianxin100() > 0) { $pos = strpos(basename($img_original), '.'); $newname = dirname($img_original) . '/' . $GLOBALS['image']->random_filename() . substr(basename($img_original), $pos); copy(WEB_PATH . $img_original, WEB_PATH . $newname); $img_url = $newname; $GLOBALS['image']->add_watermark(WEB_PATH . $img_url, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']); } /* 重新格式化图片名称 */ $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'); $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); /* 不保留商品原图的时候删除原图 */ 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(WEB_PATH . $img_original); } } elseif (!empty($image_urls[$key]) && $image_urls[$key] != $GLOBALS['_LANG']['img_file'] && $image_urls[$key] != 'http://' && copy(trim($image_urls[$key]), WEB_PATH . 'temp/' . basename($image_urls[$key]))) { $image_url = trim($image_urls[$key]); //定义原图路径 $down_img = WEB_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); } } }
$smarty->assign('user_rank_list', get_user_rank_list()); $smarty->assign('weight_unit', $is_add ? '1' : ($goods['goods_weight'] >= 1 ? '1' : '0.001')); $smarty->assign('cfg', $_CFG); $smarty->assign('form_act', $is_add ? 'insert' : ($_REQUEST['act'] == 'edit' ? 'update' : 'insert')); if ($_REQUEST['act'] == 'add' || $_REQUEST['act'] == 'edit') { $smarty->assign('is_add', true); } if (!$is_add) { $smarty->assign('member_price_list', get_member_price_list($_REQUEST['goods_id'])); } $smarty->assign('link_goods_list', $link_goods_list); $smarty->assign('group_goods_list', $group_goods_list); $smarty->assign('goods_article_list', $goods_article_list); $smarty->assign('img_list', $img_list); $smarty->assign('goods_type_list', goods_type_list($goods['goods_type'])); $smarty->assign('gd', gd_version_tianxin100()); $smarty->assign('thumb_width', $_CFG['thumb_width']); $smarty->assign('thumb_height', $_CFG['thumb_height']); $smarty->assign('goods_attr_html', build_attr_html($goods['goods_type'], $goods['goods_id'])); $volume_price_list = ''; if (isset($_REQUEST['goods_id'])) { $volume_price_list = get_volume_price_list($_REQUEST['goods_id']); } if (empty($volume_price_list)) { $volume_price_list = array('0' => array('number' => '', 'price' => '')); } $smarty->assign('volume_price_list', $volume_price_list); /* 显示商品信息页面 */ assign_query_info(); $smarty->display('goods_info.htm'); } elseif ($_REQUEST['act'] == 'insert' || $_REQUEST['act'] == 'update') {