ECSHOP商品分类添加图片广告二次开发教程

2016-06-13 13:05 来源:www.chinab4c.com 作者:ecshop专家

1、给xxx_category表增加一个varchar类型的category_img字段,用来存储上传的图片路径字符串alter table  `ecs_category` add cat_img varchar(255)alter table  `ecs_category` add cat_img_link varchar(255) 2、网站目录/admin/category.php(1)查找    $exc = new exchange($ecs->table("category"), $db, 'cat_id', 'cat_name');这一语句,并在该语句下面大约行20增加:    include_once(ROOT_PATH . '/includes/cls_image.php');    $image = new cls_image($_CFG['bgcolor']);    // 最大上传文件大小    $php_maxsize = ini_get('upload_max_filesize');    $htm_maxsize = '2M';(2)查找    $cat['cat_recommend']  = !empty($_POST['cat_recommend'])  ? $_POST['cat_recommend'] : array();并在该语句下面大约行111增加:$cat['cat_img']      = '';  //自定义上传分类图    $cat['cat_img_link']  = !empty($_POST['cat_img_link'])    ? trim($_POST['cat_img_link']) : '';    //检查是否有上传分类图片    if (isset($_FILES['cat_img']))    {      //如果有错误      if($_FILES['cat_img']['error'])      {      if ($_FILES['cat_img']['error'] == 0)      {        if (!$image->check_img_type($_FILES['cat_img']['type']))        {        sys_msg("上传的分类图类型无效", 1, array(), false);        }      }      elseif ($_FILES['cat_img']['error'] == 1)      {        sys_msg(sprintf("上传的分类图超过了大小", $php_maxsize), 1, array(), false);      }      elseif ($_FILES['cat_img']['error'] == 2)      {        sys_msg(sprintf("上传的分类图超过了大小", $htm_maxsize), 1, array(), false);      }      }      else  //没有错误检查是否存在temp目录      {      if ($_FILES['cat_img']['tmp_name'] != 'none')      {        if (!$image->check_img_type($_FILES['cat_img']['type']))        {        sys_msg('无效的分类图片', 1, array(), false);        }      }      }      //如果上传了分类图,则进行相应处理      if ($_FILES['cat_img']['tmp_name'] != '' && $_FILES['cat_img']['tmp_name'] != 'none')      {      $catimg  = $image->upload_image($_FILES['cat_img']); // 上传的商品色彩图      if ($catimg === false)      {        sys_msg($image->error_msg(), 1, array(), false);      }      else      {        $cat['cat_img'] = $catimg;      }      }     }(3)查找下一段    $cat['cat_recommend']  = !empty($_POST['cat_recommend'])  ? $_POST['cat_recommend'] : array();并在该语句下面大约行323增加:$issave_catimg      = !empty($_POST['issave_catimg']) ? intval($_POST['issave_catimg']) : 1;    $cat['cat_img_link']  = !empty($_POST['cat_img_link'])    ? trim($_POST['cat_img_link']) : '';            //检查是否有上传分类图片            if (isset($_FILES['cat_img']))            {                      //如果有错误                      if($_FILES['cat_img']['error'])                      {                                if ($_FILES['cat_img']['error'] == 0)                                {                                        if (!$image->check_img_type($_FILES['cat_img']['type']))                                        {                                                  sys_msg("上传的分类图类型无效", 1, array(), false);                                        }                                }                                elseif ($_FILES['cat_img']['error'] == 1)                                {                                        sys_msg(sprintf("上传的分类图超过了大小", $php_maxsize), 1, array(), false);                                }                                elseif ($_FILES['cat_img']['error'] == 2)                                {                                        sys_msg(sprintf("上传的分类图超过了大小", $htm_maxsize), 1, array(), false);                                }                      }                      else  //没有错误检查是否存在temp目录                      {                                if ($_FILES['cat_img']['tmp_name'] != 'none')                                {                                        if (!$image->check_img_type($_FILES['cat_img']['type']))                                        {                                                  sys_msg('无效的分类图片', 1, array(), false);                                        }                                }                      }                      //如果上传了分类图,则进行相应处理                      if ($_FILES['cat_img']['tmp_name'] != '' && $_FILES['cat_img']['tmp_name'] != 'none')                      {                                $catimg  = $image->upload_image($_FILES['cat_img']); // 上传的商品色彩图                                if ($catimg === false)                                {                                        sys_msg($image->error_msg(), 1, array(), false);                                }                                else                                {                                        $cat['cat_img'] = $catimg;                                }                                //检查是否存在上传的分类图,如果有则删除                                $cat_img = $db->getOne('SELECT cat_img FROM ' .$ecs->table('category'). " WHERE cat_id='$cat_id'");                                if($cat_img != '' && is_file('../' . $cat_img))                                {                                        @unlink('../' . $cat_img);                                }                              }            }            if($issave_catimg == 2)            {                      //检查是否存在上传的分类图,如果有则删除                      $cat_img = $db->getOne('SELECT cat_img FROM ' .$ecs->table('category'). " WHERE cat_id='$cat_id'");                      if($cat_img != '' && is_file('../' . $cat_img))                      {                                @unlink('../' . $cat_img);                                $cat['cat_img'] = '';                      }            }(4)查找    if ($cat_count == 0 && $goods_count == 0)      {并在该行下面大约691增加:    //检查是否存在上传的分类图,如果有则删除                  $cat_img = $db->getOne('SELECT cat_img FROM ' .$ecs->table('category'). " WHERE cat_id='$cat_id'");                  if($cat_img != '' && is_file('../' . $cat_img))                  {                            @unlink('../' . $cat_img);                  }三、网站目录/category.php(1)查找$smarty->display('category.dwt', $cache_id);在该语句上面大约行396增加:    //获取自定义分类增加的信息    $cat_id = intval($_REQUEST['id']);    $sql = "SELECT * FROM " .$GLOBALS['ecs']->table('category'). " WHERE cat_id='$cat_id' LIMIT 1";    $cat_info  = $GLOBALS['db']->getRow($sql);    if($cat_info)    {    $cat_img      = $cat_info['cat_img'];    $cat_img_link = $cat_info['cat_img_link'];    $smarty->assign('cat_img', $cat_img);    $smarty->assign('cat_img_link', $cat_img_link);    }四、打开admin/templates/category_info.htm(1)找到                                        在该代码下面增加:                        五、打开网站目录/themes/当前使用的模板/category.dwt在下增加代码:{if $cat_img}                                                   {/if}{$lang.cat_desc}:自定义分类图:        {if $cat_info.cat_img}        是否保留当前的分类图:    是    否    {else}        {/if}   分类图链接地址: