Ecshop商品新增加一个图片上传功能

ecshop商品新增加一个图片上传功能

数据库修改

在goods表中增加字段

tuijie_img varchar(255)

ALTER TABLE `tlxj_goods` ADD `tuijie_img` VARCHAR( 255 ) NOT NULL

在/admin/templates/goods_info.htm中增加代码

<tr>

<td class="label">上传商品推介图片:</td>

<td>

<input type="file" name="tuijie_img" size="35" />

{if $goods.tuijie_img}

<a href="goods.php?act=show_image&img_url={$goods.tuijie_img}" target="_blank"><img src="images/yes.gif" border="0" /></a>

{else}

<img src="images/no.gif" />

{/if}

</td>

</tr>

在/admin/goods.php中

在代码

$goods_thumb = (empty($goods_thumb) && isset($_POST['auto_thumb']))? $goods_img : $goods_thumb;

后面增加代码

//$tuijie_img_name = basename($image->upload_image($_FILES['tuijie_img'],'tuijie_img'));

//$tuijie_img = '/data/tuijie_img/'. $tuijie_img_name;

$tuijie_img = $image->upload_image($_FILES['tuijie_img']);

把代码

if ($is_insert)

{

if ($code == '')

{

$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

"cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .

"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id, danweijiage)" .

"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

"'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".

" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id', '$_POST[danweijiage]')";

}

else

{

$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

"cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .

"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral, danweijiage)" .

"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

"'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".

" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral', '$_POST[danweijiage]')";

}

}

修改为

if ($is_insert)

{

if ($code == '')

{

$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

"cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " .

"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, rank_integral, suppliers_id, danweijiage, tuijie_img)" .

"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

"'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', '$is_on_sale', '$is_alone_sale', $is_shipping, ".

" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$rank_integral', '$suppliers_id', '$_POST[danweijiage]', '$tuijie_img')";

}

else

{

$sql = "INSERT INTO " . $ecs->table('goods') . " (goods_name, goods_name_style, goods_sn, " .

"cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " .

"promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " .

"seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " .

"is_on_sale, is_alone_sale, is_shipping, goods_desc, add_time, last_update, goods_type, extension_code, rank_integral, danweijiage, tuijie_img)" .

"VALUES ('$_POST[goods_name]', '$goods_name_style', '$goods_sn', '$catgory_id', " .

"'$brand_id', '$shop_price', '$market_price', '$is_promote','$promote_price', ".

"'$promote_start_date', '$promote_end_date', '$goods_img', '$goods_thumb', '$original_img', ".

"'$_POST[keywords]', '$_POST[goods_brief]', '$_POST[seller_note]', '$goods_weight', '$goods_number',".

" '$warn_number', '$_POST[integral]', '$give_integral', '$is_best', '$is_new', '$is_hot', 0, '$is_on_sale', '$is_alone_sale', $is_shipping, ".

" '$_POST[goods_desc]', '" . gmtime() . "', '". gmtime() ."', '$goods_type', '$code', '$rank_integral', '$_POST[danweijiage]', '$tuijie_img')";

}

}

在代码

$sql = "SELECT goods_thumb, goods_img, original_img " .

" FROM " . $ecs->table('goods') .

" WHERE goods_id = '$_REQUEST[goods_id]'";

$row = $db->getRow($sql);

if ($proc_thumb && $goods_img && $row['goods_img'] && !goods_parse_url($row['goods_img']))

{

@unlink(ROOT_PATH . $row['goods_img']);

@unlink(ROOT_PATH . $row['original_img']);

}

if ($proc_thumb && $goods_thumb && $row['goods_thumb'] && !goods_parse_url($row['goods_thumb']))

{

@unlink(ROOT_PATH . $row['goods_thumb']);

}

后面增加代码

$sql = "SELECT tuijie_img" .

" FROM " . $ecs->table('goods') .

" WHERE goods_id = '$_REQUEST[goods_id]'";

$row = $db->getRow($sql);

if ($row['tuijie_img'])

{

@unlink(ROOT_PATH . $row['tuijie_img']);

}

在代码

if ($goods_img)

{

$sql .= "goods_img = '$goods_img', original_img = '$original_img', ";

}

if ($goods_thumb)

{

$sql .= "goods_thumb = '$goods_thumb', ";

}

后面增加代码

if($tuijie_img)

{

$sql .= "tuijie_img = '$tuijie_img', ";

}

文章转载:http://www.gehut.cn/

(0)

相关推荐