Authored by Rock Zhang

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

... ... @@ -133,14 +133,8 @@ class Images
{
$images[$files['name']] = $files['tmp_name'];
}
if($_SERVER['HTTP_HOST'] != 'test.service.api.yohobuy.com') //代理转接
{
return self::agentCurlImage($images);
}
else
{
return self::uploadStreamImage($images);
}
return self::uploadStreamImage($images);
}
/**
... ... @@ -199,43 +193,6 @@ class Images
}
}
/**
* 代理上传图片
*
* @param array|string $files
* @return array
*/
private static function agentCurlImage($file)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, 'http://test.service.api.yohobuy.com/sns/ajax/uploadimg');
curl_setopt($ch, CURLOPT_POST, true);
$params = array();
$files = is_array($file) ? $file : array($file);
foreach($files as $key => $name)
{
$key = is_numeric($key) ? $key.'.jpg' : $key;
$filename = dirname($name).'/'.$key;
rename($name, $filename);
if (@class_exists('\CURLFile'))
{
$params["images[$key]"] = new \CURLFile(realpath($filename));
}
else
{
$params["images[$key]"] = '@' . realpath($filename);
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = json_decode(curl_exec($ch), true);
return $response['data'];
}
/**
* 获取模板的图片地址
* @param $fileName
... ...
... ... @@ -370,7 +370,8 @@ class HomeController extends AbstractAction
/**
* 意见反馈-提交表单页面
*/
public function suggestSubAction() {
public function suggestSubAction()
{
// 设置网站标题
$this->setTitle('反馈问题');
... ... @@ -398,13 +399,12 @@ class HomeController extends AbstractAction
/**
* 异步上传图片
*/
public function suggestimgUploadAction() {
if ($this->isAjax()) {
$filename = $this->get('filename', '');
$result = \Plugin\Images::saveImage($filename);
public function suggestimgUploadAction()
{
$filename = $this->post('filename', '');
$result = \Index\UserModel::saveSuggestImg($filename);
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ...
... ... @@ -370,6 +370,25 @@ class UserModel
}
/**
* 图片上传
*
* @return array|mixed 保存意见反馈数据之后的返回
*/
public static function saveSuggestImg($filename)
{
$result = array();
if (!isset($_FILES[$filename])) {
$result['code'] = 400;
$result['message'] = '文件上传错误';
} else {
$result = Images::saveImage($filename);
}
return $result;
}
/**
* 保存意见反馈数据
*
* @param int $uid 用户ID
... ...