/** * 上传资源文件 * @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 $resourceKey * @param $resourceUrl */ private function addToMap($resourceKey, $resourceUrl) { $resource = ShopResourceFile::whereRaw("resourcekey=:resourcekey", array(":resourcekey" => $resourceKey))->first(); if (!$resource instanceof ShopResourceFile) { $resource = new ShopResourceFile(); } $resource->resourceKey($resourceKey); $resource->resourceUrl($resourceUrl); $resource->save(); }