Upload.php
2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
*
* @author tongdesheng
*
*/
class YHMApi_App_V1_Upload extends YHMApi_App_V1_Base
{
/**
*
* @param array $params
* @param string $fields
*/
public static function image(array $params, $fields = '*')
{
if (empty($params['bucket'])) {
$params['bucket'] = 'yhfair';
}
if (empty($params['thumb_info'])) {
return self::result(400, '缩略图信息不能为空.');
}
$thumbInfo = $params['thumb_info'];
if (empty($thumbInfo)) {
return self::result(500, '缩略图信息数据包错误.');
}
$thumbInfo = explode('x', $thumbInfo);
if (count($thumbInfo) != 2) {
return self::result(500, '缩略图width x height数据错误.');
}
list($width, $height) = $thumbInfo;
if (empty($_FILES)) {
return self::result(400, '上传对象不能为空.');
}
$mode = 1;
if (!empty($params['mode'])) {
$mode = $params['mode'];
}
$bucket = $params['bucket'];
try {
$upload = new YHMUpload_Qiniu_Upload($bucket);
$uploadResult = $upload->uploadFile();
if (empty($uploadResult['hit'])) {
return self::result(500, '上传文件失败', $uploadResult);
}
$resultImages = array();
foreach ($uploadResult['hit'] as $key => $imagePath) {
if (($imagePath=="")||($imagePath=="null"))
{
return self::result(400, '图片上传失败.');
}
$resultImages[] = array(
'image_path' => $imagePath,
'bucket' => $params['bucket'],
'image_url' => YHMUpload_Images::view($imagePath, $width, $height, $mode, $bucket)
);
}
} catch (Exception $e) {
return self::result(500, $e->getMessage());
}
return self::result(200, '上传成功', $resultImages);
}
}