Authored by Rock Zhang

修复意见反馈图片上传接接口的问题

@@ -133,14 +133,8 @@ class Images @@ -133,14 +133,8 @@ class Images
133 { 133 {
134 $images[$files['name']] = $files['tmp_name']; 134 $images[$files['name']] = $files['tmp_name'];
135 } 135 }
136 - if($_SERVER['HTTP_HOST'] != 'test.service.api.yohobuy.com') //代理转接  
137 - {  
138 - return self::agentCurlImage($images);  
139 - }  
140 - else  
141 - {  
142 - return self::uploadStreamImage($images);  
143 - } 136 +
  137 + return self::uploadStreamImage($images);
144 } 138 }
145 139
146 /** 140 /**
@@ -199,43 +193,6 @@ class Images @@ -199,43 +193,6 @@ class Images
199 } 193 }
200 } 194 }
201 195
202 - /**  
203 - * 代理上传图片  
204 - *  
205 - * @param array|string $files  
206 - * @return array  
207 - */  
208 - private static function agentCurlImage($file)  
209 - {  
210 - $ch = curl_init();  
211 - curl_setopt($ch, CURLOPT_HEADER, 0);  
212 - curl_setopt($ch, CURLOPT_VERBOSE, 0);  
213 - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
214 - curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");  
215 - curl_setopt($ch, CURLOPT_URL, 'http://test.service.api.yohobuy.com/sns/ajax/uploadimg');  
216 - curl_setopt($ch, CURLOPT_POST, true);  
217 - $params = array();  
218 - $files = is_array($file) ? $file : array($file);  
219 - foreach($files as $key => $name)  
220 - {  
221 - $key = is_numeric($key) ? $key.'.jpg' : $key;  
222 - $filename = dirname($name).'/'.$key;  
223 - rename($name, $filename);  
224 - if (@class_exists('\CURLFile'))  
225 - {  
226 - $params["images[$key]"] = new \CURLFile(realpath($filename));  
227 - }  
228 - else  
229 - {  
230 - $params["images[$key]"] = '@' . realpath($filename);  
231 - }  
232 - }  
233 - curl_setopt($ch, CURLOPT_POSTFIELDS, $params);  
234 - $response = json_decode(curl_exec($ch), true);  
235 - return $response['data'];  
236 -  
237 - }  
238 -  
239 /** 196 /**
240 * 获取模板的图片地址 197 * 获取模板的图片地址
241 * @param $fileName 198 * @param $fileName
@@ -370,7 +370,8 @@ class HomeController extends AbstractAction @@ -370,7 +370,8 @@ class HomeController extends AbstractAction
370 /** 370 /**
371 * 意见反馈-提交表单页面 371 * 意见反馈-提交表单页面
372 */ 372 */
373 - public function suggestSubAction() { 373 + public function suggestSubAction()
  374 + {
374 375
375 // 设置网站标题 376 // 设置网站标题
376 $this->setTitle('反馈问题'); 377 $this->setTitle('反馈问题');
@@ -398,13 +399,12 @@ class HomeController extends AbstractAction @@ -398,13 +399,12 @@ class HomeController extends AbstractAction
398 /** 399 /**
399 * 异步上传图片 400 * 异步上传图片
400 */ 401 */
401 - public function suggestimgUploadAction() {  
402 - if ($this->isAjax()) {  
403 - $filename = $this->get('filename', '');  
404 - $result = \Plugin\Images::saveImage($filename); 402 + public function suggestimgUploadAction()
  403 + {
  404 + $filename = $this->post('filename', '');
  405 + $result = \Index\UserModel::saveSuggestImg($filename);
405 406
406 - $this->echoJson($result);  
407 - } 407 + $this->echoJson($result);
408 } 408 }
409 409
410 /** 410 /**
@@ -370,6 +370,25 @@ class UserModel @@ -370,6 +370,25 @@ class UserModel
370 } 370 }
371 371
372 /** 372 /**
  373 + * 图片上传
  374 + *
  375 + * @return array|mixed 保存意见反馈数据之后的返回
  376 + */
  377 + public static function saveSuggestImg($filename)
  378 + {
  379 + $result = array();
  380 +
  381 + if (!isset($_FILES[$filename])) {
  382 + $result['code'] = 400;
  383 + $result['message'] = '文件上传错误';
  384 + } else {
  385 + $result = Images::saveImage($filename);
  386 + }
  387 +
  388 + return $result;
  389 + }
  390 +
  391 + /**
373 * 保存意见反馈数据 392 * 保存意见反馈数据
374 * 393 *
375 * @param int $uid 用户ID 394 * @param int $uid 用户ID