Zencart后台删除产品后图片也相对应地删除
有人问:” lightinbox版里能不能实现在后台删除商品时也同时删除空间的的图,因为空间的图太多了 都在一个文件夹里面,要去删掉很难找”:很多用zencart系统的朋友,想删除产品时把相对应的图片也给删除了,就是为了可以节省到很多没必要的空间,从而也提高了网站的显示速度. 有二种方法可以解决这个问题.
第一个方法: 后台添加产品时候,添加图片的下面,
有一句话,Delete Image? NOTE: Removes Image from Product, Image is NOT removed from server: No Yes选择NO就行了。不过好像只会删除主图,不会删除附加图。
第二种方法是在程序里去实现.那样就不用去一个个选NO 或是 YES了.他可以将主图的大,中,小图全部都删除掉.
改文件adminincludesmodulesdelete_product_confirm.php 第48行
for ($k=0, $m=sizeof($product_categories); $k<$m; $k++) { $products_image_aa=$db->Execute(“select * from products
where products_id = ‘” . (int)$product_id . “‘”);
$products_image_ct =explode(“,”, $products_image_aa->fields[‘products_image’]);
$products_image_count=count($products_image_ct);
if($products_image_count>0){
for($i=0;$i<$products_image_count;$i++){ $images_n=explode(“/”, $products_image_ct[$i]); $filepath1 = “..imagesv” . “” . $images_n[1]. “” . $images_n[2]; $filepath2 = “..imagess” . “”. $images_n[1]. “” . $images_n[2]; $filepath3 = “..imagesl” . “”. $images_n[1]. “” . $images_n[2]; unlink( $filepath1 ) ; unlink( $filepath2 ) ; unlink( $filepath3 ) ; } } $db->Execute(“delete from ” . TABLE_PRODUCTS_TO_CATEGORIES . ”
where products_id = ‘” . (int)$product_id . “‘
and categories_id = ‘” . (int)$product_categories[$k] . “‘”);
}
如果是在本地,他们的路径方式显示不同,就改成如下:
$filepath1 = “../images/v” . “/” . $images_n[1]. “/” . $images_n[2];
$filepath2 = “../images/s” . “/”. $images_n[1]. “/” . $images_n[2];
$filepath3 = “../images/l” . “/”. $images_n[1]. “/” . $images_n[2];
这里我就只开发得主图的删除.
如果想删除里面产品的相关图片(多图片产品),那么就要接着开发.个人思路分享,如果是批量上传的,图片名会很有规律.例如:主图名是1violet.jpg 那么他的另几个图是1violet_1.jpg或都是其他有规律的名称,那就如以下步骤做.
1. 取出这个产品的图片名称和这个图片所在的是路径
2. 写个程序读取这个这个产品图片路径下的所有图片名称
3. 用程序取出相关的,一起删了.
如果不是批量,是用手动上传的,那你就要看看图片名称有没有规律,如果没有,就要去数据库里找了.
还有没有更多更好的方法,高手们,如果有给点更好的意见.
Need a translation service?
Please enter your personal details and we will contact you shortly
Words translated by CCJK
146,096,379Over 95% of our clients recommend our language services to others