Authored by 周少峰

upload image return

... ... @@ -106,9 +106,8 @@ class Images
/**
* 图片上传
* @param string $name 文件表单name, 即用于$_FILES[$name]
* @param string $path
*/
public static function saveImage($name, $path = 'suggest')
public static function saveImage($name)
{
if (empty($_FILES[$name])) {
return array();
... ... @@ -125,7 +124,7 @@ class Images
$images[$files['name']] = $files['tmp_name'];
}
return self::uploadStreamImage($images, $path);
return self::uploadStreamImage($images);
}
/**
... ... @@ -133,10 +132,9 @@ class Images
*
* @param string | array(filename => absolute file path) $file
* url:http://upload.static.yohobuy.com?project=sns&fileData=xxx
* @param string $path
* @return mixed
*/
public static function uploadStreamImage($file, $path = 'suggest')
public static function uploadStreamImage($file)
{
$end = "\r\n";
$twoHyphens = "--";
... ... @@ -160,7 +158,7 @@ class Images
$stream .= $twoHyphens . $boundary . $end;
$stream .="Content-Disposition: form-data; " . "name=\"project\"" . $end;
$stream .= $end;
$stream .= $path; //project sns
$stream .= 'suggest'; //project sns
$stream .= $end;
$stream .= $twoHyphens . $boundary . $twoHyphens . $end;
$opts = array(
... ... @@ -179,14 +177,14 @@ class Images
if (count($file) == 1 || !is_array($file)) {
$imgRelUrl = current($result['data']['imagesList']);
$imgList['imgList'][] = array(
'imgUrl' => self::getSourceUrl($imgRelUrl, $path) . $imgExtra,
'imgUrl' => self::getSourceUrl($imgRelUrl, 'suggest') . $imgExtra,
'imgRelUrl' => $imgRelUrl
);
} else {
$img = array();
foreach ($result['data']['imagesList'] as $val) {
$img = array();
$img['imgUrl'] = self::getSourceUrl($val, $path) . $imgExtra;
$img['imgUrl'] = self::getSourceUrl($val, 'suggest') . $imgExtra;
$img['imgRelUrl'] = $val;
$imgList['imgList'][] = $img;
}
... ...
... ... @@ -479,7 +479,7 @@ class ReturnsModel
// if (!in_array($_FILES['fileData']['type'],$type)) {
// return array('code'=>'400','message'=>'图片格式错误');
// }
$result = Images::saveImage($filename, 'evidenceImages');
$result = Images::saveImage($filename);
}
return $result;
... ...