PHP方法:
/**
 * 七牛云商品图片删除2017/10/25
 */
public function delGoodsImg() {
   $this->isShopLogin();
   $img = I("imgUrl");
   $res = $this->qiNiuDelImg($img);

   if ($res['status'] != 1) {
      //七牛里没有图片时,但数据库里有数据时
      if (!empty($res['err']) && !empty($img)) {
         $gg = M("goods_gallerys");
         $where['goodsImg'] = "http://ang.com/" . $img;
         $imgInfo = $gg->where($where)->find();
         if (!empty($imgInfo)) {
            $res = $gg->where($where)->delete();
         }
      }
      $this->ajaxReturn($res['err']);
   } else {
      $gg = M("goods_gallerys");
      $where['goodsImg'] = "http:/g.com/" . $img;
      $imgInfo = $gg->where($where)->find();
      if (!empty($imgInfo)) {
         $res = $gg->where($where)->delete();
      }

      $this->ajaxReturn("ok");
   }
}

配置删除路径 :

var delimg="{:U('Home/Goods/delGoodsImg')}";
//删除退货上传的图片
        $(document).on("click",".lst1106-SC", function(){
            $(this).parent().remove();
            var imgSrc = $(this).parent().children('img').attr('src');
            var index = imgSrc.lastIndexOf("\/");
            var name = imgSrc.substring(index + 1,imgSrc.length);
        console.log(imgSrc)
        console.log(name)
        $.post(delimg, { imgUrl: name }, function(data) {
               console.log(data);
            });
        });

打印结果:
http://image.jianfengwang.com/o_1c43gn8k15e01ia0tt0898fe9.jpg
 o_1c43gn8k15e01ia0tt0898fe9.jpg
 ok
 

 

posted on 2018-01-18 10:25  刘世涛6192  阅读(4353)  评论(0编辑  收藏  举报