public static function attachKey($crud = []) { if (empty($crud)) { return []; } $array = []; foreach ($crud as $img) { $name = Img::getFileName($img); $key = Img::getKey($name); if (!$key) { continue; } $array[$key] = trim($img); } return $array; }
public function delProductImg($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id'); $obj = Input::get('obj', ''); try { $user = User::chkUserByToken($token, $u_id); $product = Product::find($id); if (empty($product)) { throw new Exception("没有找到请求的图片", 7001); } $imgs = explode(',', $product->p_imgs); foreach ($imgs as $key => $img) { if ($obj == $img) { unset($imgs[$key]); break; } } $product->p_imgs = implode(',', $imgs); $product->save(); $oss = new AliyunOss('product'); $obj = Img::getFileName('obj'); $obj = 'product/' . $id . '/' . $obj; $oss->remove($obj); $re = Tools::reTrue('删除图片成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '删除图片失败:' . $e->getMessage()); } return Response::json($re); }
public function replace($name) { $tmp_imgs = $this->getTmpList(); $imgs = $this->getList(); // delete if (array_key_exists($name, $imgs)) { $this->remove($imgs[$name]); } // move if (array_key_exists($name, $tmp_imgs)) { $obj = Img::getFileName($tmp_imgs[$name]); $dir = $this->_cate . '/' . $this->_id . '/'; $obj = $dir . $obj; $this->move($tmp_imgs[$name], $obj); } else { throw new Exception("没有找到目标文件", 20001); } return $obj; }