/** * 上传资源文件 * @param array $fileInputName * @param array $del * @return array * @throws DeepInException * @throws DeepInHtmlException */ public static function upload($fileInputName = array(), $del = array()) { if (!is_array($fileInputName)) { throw new DeepInException("参数必须是文件表单域组成的数组~!"); } if (empty($fileInputName)) { throw new DeepInException("没有需要上传的图片~!"); } $upload = new DeepInUpload(env("UPLOAD_SERVER_URL")); $ret = array(); foreach ($fileInputName as $val) { if (\Input::hasFile($val)) { $filePath = \Input::file($val); $responseVal = $upload->toUpload($filePath, "png"); $authResponse = $responseVal->getAuthResponseValue(); $resourceMap = new ShopResourceFile(); $resourceMap->resourceKey($authResponse->getResourceUrl()); $resourceMap->resourceUrl($responseVal->getUpYunUrlResponseValue()->getLocation()); if ($resourceMap->save() == false) { throw new DeepInHtmlException("保存又拍云图片地址失败~!"); } $ret[$val] = $authResponse->getResourceUrl(); } } return $ret; }
/** * 应用图片 * @param DeepInUpload $upload */ protected function app(DeepInUpload $upload) { $appList = ShopApps::all(); foreach ($appList as $item) { if ($item instanceof ShopApps) { $imgView = $item->imgView(); if (empty($imgView)) { continue; } $response = $upload->getUpYunUrl($imgView); $responseValue = $response->getResponseValue(); if ($responseValue instanceof UpYunResponseValue) { $this->addToMap($imgView, $responseValue->getLocation()); } } } }