Passed
Push — master ( 103d2b...e57950 )
by xiaohui
02:15
created
sdk/Utils/UploadOption.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -6,166 +6,166 @@  discard block
 block discarded – undo
6 6
 
7 7
 class UploadOption
8 8
 {
9
-    /*optionType用于标识UploadOption的类型,即:普通上传、初始化分片上传、分片上传、分片上传完成*/
10
-    public $optionType;
9
+	/*optionType用于标识UploadOption的类型,即:普通上传、初始化分片上传、分片上传、分片上传完成*/
10
+	public $optionType;
11 11
 
12
-    /*以下属性是上传时的可选参数。即Rest API中Http请求Body中所需的可选参数*/
13
-    public $dir;                                    // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效)
14
-    public $name;                                   // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效)
15
-    public $metaArray;                              // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名)
16
-    public $varArray;                               // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名)
17
-    private $md5;                                   // 文件md5值(推荐提供此参数进行一致性检查)
18
-    private $size;                                  // 文件大小
19
-    private $content;                               // 文件内容(在http请求体Body中必须位于参数的最后一位)
12
+	/*以下属性是上传时的可选参数。即Rest API中Http请求Body中所需的可选参数*/
13
+	public $dir;                                    // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效)
14
+	public $name;                                   // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效)
15
+	public $metaArray;                              // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名)
16
+	public $varArray;                               // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名)
17
+	private $md5;                                   // 文件md5值(推荐提供此参数进行一致性检查)
18
+	private $size;                                  // 文件大小
19
+	private $content;                               // 文件内容(在http请求体Body中必须位于参数的最后一位)
20 20
 
21
-    /*以下属性是用户根据自己应用需求,可选的配置*/
22
-    public $blockSize;                              // 文件分片的大小。针对分片上传。
23
-    public $timeout;                                // 进行http连接的超时时间
24
-    public $httpReTry;                              // http失败自动重试。0 or 1
21
+	/*以下属性是用户根据自己应用需求,可选的配置*/
22
+	public $blockSize;                              // 文件分片的大小。针对分片上传。
23
+	public $timeout;                                // 进行http连接的超时时间
24
+	public $httpReTry;                              // http失败自动重试。0 or 1
25 25
 
26
-    /*以下属性是用于分片上传时的参数,仅用于分片上传。用户在调用分片上传时可以选择配置。*/
27
-    private $uploadId;                              // OSS分片上传ID(OSS用于区分上传的id)
28
-    private $uniqueId;                              // 服务上传唯一ID(多媒体服务用于区分上传的id)
29
-    private $partNumber;                            // 分片文件块上传成功后返回的文件块编号
30
-    private $eTag;                                  // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成)
31
-    private $array_PartNum_ETag;                    // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag
26
+	/*以下属性是用于分片上传时的参数,仅用于分片上传。用户在调用分片上传时可以选择配置。*/
27
+	private $uploadId;                              // OSS分片上传ID(OSS用于区分上传的id)
28
+	private $uniqueId;                              // 服务上传唯一ID(多媒体服务用于区分上传的id)
29
+	private $partNumber;                            // 分片文件块上传成功后返回的文件块编号
30
+	private $eTag;                                  // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成)
31
+	private $array_PartNum_ETag;                    // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag
32 32
 
33
-    public function __construct()
34
-    {
35
-        $this->optionType = UpOptionType::COMMON_UPLOAD_TYPE; //默认普通上传类型
36
-        $this->metaArray = array();
37
-        $this->varArray = array();
38
-        $this->blockSize = Conf::BLOCK_DEFF_SIZE;   //默认2M
39
-        $this->timeout = Conf::HTTP_TIMEOUT;        //默认超时30s
40
-        $this->httpReTry = Conf::HTTP_RETRY;       //默认重试
41
-        $this->array_PartNum_ETag = array();
42
-    }
43
-    /**得到上传时http请求体所需的参数*/
44
-    public function getParaArray()
45
-    {
46
-        switch ($this->optionType) {
47
-            case UpOptionType::COMMON_UPLOAD_TYPE:
48
-            case UpOptionType::BLOCK_INIT_UPLOAD:
49
-                return $this->getParas_Common_BlockInit();
50
-            case UpOptionType::BLOCK_RUN_UPLOAD:
51
-                return $this->getParas_BlockRun();
52
-            case UpOptionType::BLOCK_COMPLETE_UPLOAD:
53
-                return $this->getParas_BlockComplete();
54
-            case UpOptionType::BLOCK_CANCEL_UPLOAD:
55
-                return $this->getParas_BlockCancel();
56
-            default:
57
-                return null;
58
-        }
59
-    }
60
-    /** 构造 普通上传 或者 初始化分片上传 所需的参数 */
61
-    private function getParas_Common_BlockInit()
62
-    {
63
-        $paraArray = array();
64
-        if (isset($this->dir)) {
65
-            $paraArray['dir'] = $this->dir;
66
-        }
67
-        if (isset($this->name)) {
68
-            $paraArray['name'] = $this->name;
69
-        }
70
-        $paraArray['md5'] = md5($this->content); // 计算文件md5
71
-        $paraArray['size'] = strlen($this->content); // 计算文件大小
72
-        $paraArray['content'] = $this->content;
73
-        $this->createMetaVars($paraArray, "meta", $this->metaArray);
74
-        $this->createMetaVars($paraArray, "var", $this->varArray);
75
-        return $paraArray;
76
-    }
77
-    /** 构造 分片上传过程中 所需的参数 */
78
-    private function getParas_BlockRun()
79
-    {
80
-        $paraArray = array();
81
-        $paraArray['uploadId'] = $this->uploadId;
82
-        $paraArray['id'] = $this->uniqueId;
83
-        $paraArray['partNumber'] = $this->partNumber;
84
-        $paraArray['md5'] = md5($this->content); // 计算文件md5
85
-        $paraArray['size'] = strlen($this->content); // 计算文件大小
86
-        $paraArray['content'] = $this->content;
87
-        return $paraArray;
88
-    }
89
-    /** 构造 分片上传完成时 所需的参数 */
90
-    private function getParas_BlockComplete()
91
-    {
92
-        $paraArray = array();
93
-        $paraArray['uploadId'] = $this->uploadId;
94
-        $paraArray['id'] = $this->uniqueId;
95
-        $paraArray['md5'] = $this->md5;
96
-        $parts = EncodeUtils::encodeWithURLSafeBase64(json_encode($this->array_PartNum_ETag));
97
-        $paraArray['parts'] = $parts; // 所有文件块的编号partNumber 和 标记ETag,需要进行base64的编码
98
-        return $paraArray;
99
-    }
100
-    /** 构造 分片上传取消 所需的参数 */
101
-    private function getParas_BlockCancel()
102
-    {
103
-        return array('id' => $this->uniqueId, 'uploadId' => $this->uploadId);
104
-    }
105
-    /**
106
-     * 构建上传http请求体的meta-*和var-*选项参数。将tempArr中的元素加上前缀prefix,然后保存到paraArr中
107
-     * @param array $paraArr 最终的数组
108
-     * @param string $prefix 前缀
109
-     * @param array $tempArr 待添加的数组
110
-     * @return array $paraArr 最终的数组
111
-     */
112
-    private function createMetaVars($paraArr, $prefix, $tempArr)
113
-    {
114
-        foreach ($tempArr as $key => $val) {
115
-            $key = $prefix . '-' . $key;
116
-            $paraArr[$key] = $val;
117
-        }
118
-        return $paraArr;
119
-    }
120
-    /**设置待上传的数据。该方法开发者不需要调用,该方法根据用户数据自动调用
33
+	public function __construct()
34
+	{
35
+		$this->optionType = UpOptionType::COMMON_UPLOAD_TYPE; //默认普通上传类型
36
+		$this->metaArray = array();
37
+		$this->varArray = array();
38
+		$this->blockSize = Conf::BLOCK_DEFF_SIZE;   //默认2M
39
+		$this->timeout = Conf::HTTP_TIMEOUT;        //默认超时30s
40
+		$this->httpReTry = Conf::HTTP_RETRY;       //默认重试
41
+		$this->array_PartNum_ETag = array();
42
+	}
43
+	/**得到上传时http请求体所需的参数*/
44
+	public function getParaArray()
45
+	{
46
+		switch ($this->optionType) {
47
+			case UpOptionType::COMMON_UPLOAD_TYPE:
48
+			case UpOptionType::BLOCK_INIT_UPLOAD:
49
+				return $this->getParas_Common_BlockInit();
50
+			case UpOptionType::BLOCK_RUN_UPLOAD:
51
+				return $this->getParas_BlockRun();
52
+			case UpOptionType::BLOCK_COMPLETE_UPLOAD:
53
+				return $this->getParas_BlockComplete();
54
+			case UpOptionType::BLOCK_CANCEL_UPLOAD:
55
+				return $this->getParas_BlockCancel();
56
+			default:
57
+				return null;
58
+		}
59
+	}
60
+	/** 构造 普通上传 或者 初始化分片上传 所需的参数 */
61
+	private function getParas_Common_BlockInit()
62
+	{
63
+		$paraArray = array();
64
+		if (isset($this->dir)) {
65
+			$paraArray['dir'] = $this->dir;
66
+		}
67
+		if (isset($this->name)) {
68
+			$paraArray['name'] = $this->name;
69
+		}
70
+		$paraArray['md5'] = md5($this->content); // 计算文件md5
71
+		$paraArray['size'] = strlen($this->content); // 计算文件大小
72
+		$paraArray['content'] = $this->content;
73
+		$this->createMetaVars($paraArray, "meta", $this->metaArray);
74
+		$this->createMetaVars($paraArray, "var", $this->varArray);
75
+		return $paraArray;
76
+	}
77
+	/** 构造 分片上传过程中 所需的参数 */
78
+	private function getParas_BlockRun()
79
+	{
80
+		$paraArray = array();
81
+		$paraArray['uploadId'] = $this->uploadId;
82
+		$paraArray['id'] = $this->uniqueId;
83
+		$paraArray['partNumber'] = $this->partNumber;
84
+		$paraArray['md5'] = md5($this->content); // 计算文件md5
85
+		$paraArray['size'] = strlen($this->content); // 计算文件大小
86
+		$paraArray['content'] = $this->content;
87
+		return $paraArray;
88
+	}
89
+	/** 构造 分片上传完成时 所需的参数 */
90
+	private function getParas_BlockComplete()
91
+	{
92
+		$paraArray = array();
93
+		$paraArray['uploadId'] = $this->uploadId;
94
+		$paraArray['id'] = $this->uniqueId;
95
+		$paraArray['md5'] = $this->md5;
96
+		$parts = EncodeUtils::encodeWithURLSafeBase64(json_encode($this->array_PartNum_ETag));
97
+		$paraArray['parts'] = $parts; // 所有文件块的编号partNumber 和 标记ETag,需要进行base64的编码
98
+		return $paraArray;
99
+	}
100
+	/** 构造 分片上传取消 所需的参数 */
101
+	private function getParas_BlockCancel()
102
+	{
103
+		return array('id' => $this->uniqueId, 'uploadId' => $this->uploadId);
104
+	}
105
+	/**
106
+	 * 构建上传http请求体的meta-*和var-*选项参数。将tempArr中的元素加上前缀prefix,然后保存到paraArr中
107
+	 * @param array $paraArr 最终的数组
108
+	 * @param string $prefix 前缀
109
+	 * @param array $tempArr 待添加的数组
110
+	 * @return array $paraArr 最终的数组
111
+	 */
112
+	private function createMetaVars($paraArr, $prefix, $tempArr)
113
+	{
114
+		foreach ($tempArr as $key => $val) {
115
+			$key = $prefix . '-' . $key;
116
+			$paraArr[$key] = $val;
117
+		}
118
+		return $paraArr;
119
+	}
120
+	/**设置待上传的数据。该方法开发者不需要调用,该方法根据用户数据自动调用
121 121
      * @param string $data 字符串 */
122
-    public function setContent($data)
123
-    {
124
-        $this->content = $data;
125
-    }
126
-    /**设置MD5值。该方法主要用于在分片上传完成时调用
122
+	public function setContent($data)
123
+	{
124
+		$this->content = $data;
125
+	}
126
+	/**设置MD5值。该方法主要用于在分片上传完成时调用
127 127
      * @param string $value md5值 */
128
-    public function setMd5($value)
129
-    {
130
-        $this->md5 = $value;
131
-    }
132
-    /**得到MD5值。该方法主要用于在分片上传完成时调用*/
133
-    public function getMd5()
134
-    {
135
-        return $this->md5;
136
-    }
137
-    /*下面四个函数均是用于分片上传时的设置,开发者不需要调用*/
138
-    /**分片上传时用于设置uploadId */
139
-    public function setUploadId($uploadId)
140
-    {
141
-        $this->uploadId = $uploadId;
142
-    }
143
-    /**分片上传时用于设置id */
144
-    public function setUniqueIdId($id)
145
-    {
146
-        $this->uniqueId = $id;
147
-    }
148
-    /**分片上传时,用于获取分片上传时的块编号partNumber */
149
-    public function getPartNumber()
150
-    {
151
-        return $this->partNumber;
152
-    }
153
-    /**分片上传时,用于设置分片上传时的块编号partNumber */
154
-    public function setPartNumber($partNumber)
155
-    {
156
-        $this->partNumber = $partNumber;
157
-    }
158
-    /**分片上传过程中,用于保存所有的 块编号partNumber 和 标记ETag*/
159
-    public function addPartNumberAndETag($partNumber, $eTag)
160
-    {
161
-        $this->eTag = $eTag;
162
-        array_push($this->array_PartNum_ETag, array("partNumber" => $partNumber, "eTag" => $eTag));
163
-    }
164
-    /**检测分片上传的参数。即uploadId、uniqueId是否有值*/
165
-    public function checkMutipartParas()
166
-    {
167
-        return isset($this->uploadId) && isset($this->uniqueId);
168
-    }
128
+	public function setMd5($value)
129
+	{
130
+		$this->md5 = $value;
131
+	}
132
+	/**得到MD5值。该方法主要用于在分片上传完成时调用*/
133
+	public function getMd5()
134
+	{
135
+		return $this->md5;
136
+	}
137
+	/*下面四个函数均是用于分片上传时的设置,开发者不需要调用*/
138
+	/**分片上传时用于设置uploadId */
139
+	public function setUploadId($uploadId)
140
+	{
141
+		$this->uploadId = $uploadId;
142
+	}
143
+	/**分片上传时用于设置id */
144
+	public function setUniqueIdId($id)
145
+	{
146
+		$this->uniqueId = $id;
147
+	}
148
+	/**分片上传时,用于获取分片上传时的块编号partNumber */
149
+	public function getPartNumber()
150
+	{
151
+		return $this->partNumber;
152
+	}
153
+	/**分片上传时,用于设置分片上传时的块编号partNumber */
154
+	public function setPartNumber($partNumber)
155
+	{
156
+		$this->partNumber = $partNumber;
157
+	}
158
+	/**分片上传过程中,用于保存所有的 块编号partNumber 和 标记ETag*/
159
+	public function addPartNumberAndETag($partNumber, $eTag)
160
+	{
161
+		$this->eTag = $eTag;
162
+		array_push($this->array_PartNum_ETag, array("partNumber" => $partNumber, "eTag" => $eTag));
163
+	}
164
+	/**检测分片上传的参数。即uploadId、uniqueId是否有值*/
165
+	public function checkMutipartParas()
166
+	{
167
+		return isset($this->uploadId) && isset($this->uniqueId);
168
+	}
169 169
 }
170 170
 /**
171 171
  * 用于标识UploadOption对象的类型
@@ -173,10 +173,10 @@  discard block
 block discarded – undo
173 173
  */
174 174
 class UpOptionType
175 175
 {
176
-    //下面的常量用于标识UploadOption对象适用的类型
177
-    const COMMON_UPLOAD_TYPE = 0;       //普通上传时的UploadOption类型
178
-    const BLOCK_INIT_UPLOAD = 1;        //分片初始化时的UploadOption类型
179
-    const BLOCK_RUN_UPLOAD = 2;         //分片上传过程中的UploadOption类型
180
-    const BLOCK_COMPLETE_UPLOAD = 3;    //分片上传完成时的UploadOption类型
181
-    const BLOCK_CANCEL_UPLOAD = 4;      //分片上传取消时的UploadOption类型
176
+	//下面的常量用于标识UploadOption对象适用的类型
177
+	const COMMON_UPLOAD_TYPE = 0;       //普通上传时的UploadOption类型
178
+	const BLOCK_INIT_UPLOAD = 1;        //分片初始化时的UploadOption类型
179
+	const BLOCK_RUN_UPLOAD = 2;         //分片上传过程中的UploadOption类型
180
+	const BLOCK_COMPLETE_UPLOAD = 3;    //分片上传完成时的UploadOption类型
181
+	const BLOCK_CANCEL_UPLOAD = 4;      //分片上传取消时的UploadOption类型
182 182
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -10,34 +10,34 @@  discard block
 block discarded – undo
10 10
     public $optionType;
11 11
 
12 12
     /*以下属性是上传时的可选参数。即Rest API中Http请求Body中所需的可选参数*/
13
-    public $dir;                                    // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效)
14
-    public $name;                                   // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效)
15
-    public $metaArray;                              // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名)
16
-    public $varArray;                               // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名)
17
-    private $md5;                                   // 文件md5值(推荐提供此参数进行一致性检查)
18
-    private $size;                                  // 文件大小
19
-    private $content;                               // 文件内容(在http请求体Body中必须位于参数的最后一位)
13
+    public $dir; // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效)
14
+    public $name; // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效)
15
+    public $metaArray; // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名)
16
+    public $varArray; // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名)
17
+    private $md5; // 文件md5值(推荐提供此参数进行一致性检查)
18
+    private $size; // 文件大小
19
+    private $content; // 文件内容(在http请求体Body中必须位于参数的最后一位)
20 20
 
21 21
     /*以下属性是用户根据自己应用需求,可选的配置*/
22
-    public $blockSize;                              // 文件分片的大小。针对分片上传。
23
-    public $timeout;                                // 进行http连接的超时时间
24
-    public $httpReTry;                              // http失败自动重试。0 or 1
22
+    public $blockSize; // 文件分片的大小。针对分片上传。
23
+    public $timeout; // 进行http连接的超时时间
24
+    public $httpReTry; // http失败自动重试。0 or 1
25 25
 
26 26
     /*以下属性是用于分片上传时的参数,仅用于分片上传。用户在调用分片上传时可以选择配置。*/
27
-    private $uploadId;                              // OSS分片上传ID(OSS用于区分上传的id)
28
-    private $uniqueId;                              // 服务上传唯一ID(多媒体服务用于区分上传的id)
29
-    private $partNumber;                            // 分片文件块上传成功后返回的文件块编号
30
-    private $eTag;                                  // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成)
31
-    private $array_PartNum_ETag;                    // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag
27
+    private $uploadId; // OSS分片上传ID(OSS用于区分上传的id)
28
+    private $uniqueId; // 服务上传唯一ID(多媒体服务用于区分上传的id)
29
+    private $partNumber; // 分片文件块上传成功后返回的文件块编号
30
+    private $eTag; // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成)
31
+    private $array_PartNum_ETag; // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag
32 32
 
33 33
     public function __construct()
34 34
     {
35 35
         $this->optionType = UpOptionType::COMMON_UPLOAD_TYPE; //默认普通上传类型
36 36
         $this->metaArray = array();
37 37
         $this->varArray = array();
38
-        $this->blockSize = Conf::BLOCK_DEFF_SIZE;   //默认2M
39
-        $this->timeout = Conf::HTTP_TIMEOUT;        //默认超时30s
40
-        $this->httpReTry = Conf::HTTP_RETRY;       //默认重试
38
+        $this->blockSize = Conf::BLOCK_DEFF_SIZE; //默认2M
39
+        $this->timeout = Conf::HTTP_TIMEOUT; //默认超时30s
40
+        $this->httpReTry = Conf::HTTP_RETRY; //默认重试
41 41
         $this->array_PartNum_ETag = array();
42 42
     }
43 43
     /**得到上传时http请求体所需的参数*/
@@ -174,9 +174,9 @@  discard block
 block discarded – undo
174 174
 class UpOptionType
175 175
 {
176 176
     //下面的常量用于标识UploadOption对象适用的类型
177
-    const COMMON_UPLOAD_TYPE = 0;       //普通上传时的UploadOption类型
178
-    const BLOCK_INIT_UPLOAD = 1;        //分片初始化时的UploadOption类型
179
-    const BLOCK_RUN_UPLOAD = 2;         //分片上传过程中的UploadOption类型
180
-    const BLOCK_COMPLETE_UPLOAD = 3;    //分片上传完成时的UploadOption类型
181
-    const BLOCK_CANCEL_UPLOAD = 4;      //分片上传取消时的UploadOption类型
177
+    const COMMON_UPLOAD_TYPE = 0; //普通上传时的UploadOption类型
178
+    const BLOCK_INIT_UPLOAD = 1; //分片初始化时的UploadOption类型
179
+    const BLOCK_RUN_UPLOAD = 2; //分片上传过程中的UploadOption类型
180
+    const BLOCK_COMPLETE_UPLOAD = 3; //分片上传完成时的UploadOption类型
181
+    const BLOCK_CANCEL_UPLOAD = 4; //分片上传取消时的UploadOption类型
182 182
 }
Please login to merge, or discard this patch.
sdk/Utils/UploadPolicy.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -5,47 +5,47 @@
 block discarded – undo
5 5
 
6 6
 class UploadPolicy
7 7
 {
8
-    /*如下属性是必须的[The following attributes are required]*/
9
-    public $namespace;                              // 多媒体服务的空间名[media namespace name]
10
-    public $bucket;                                 // OSS的空间名[media bucket name]
11
-    public $insertOnly;                             // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
-    public $expiration;                             // 过期时间[expiration time, unix time, in milliseconds]
8
+	/*如下属性是必须的[The following attributes are required]*/
9
+	public $namespace;                              // 多媒体服务的空间名[media namespace name]
10
+	public $bucket;                                 // OSS的空间名[media bucket name]
11
+	public $insertOnly;                             // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
+	public $expiration;                             // 过期时间[expiration time, unix time, in milliseconds]
13 13
 
14
-    /*如下属性是可选的[The following attributes are optional]*/
15
-    public $detectMime = Conf::DETECT_MIME_TRUE;                             // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
-    public $dir;                                    // 路径[media file dir, magic vars and custom vars are supported]
17
-    public $name;                                   // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
-    public $sizeLimit;                              // 文件大小限制[upload size limited, in bytes]
19
-    public $mimeLimit;                              // 文件类型限制[upload mime type limited]
20
-    public $callbackUrl;                            // 回调URL [callback urls, ip address is recommended]
21
-    public $callbackHost;                           // 回调时Host [callback host]
22
-    public $callbackBody;                           // 回调时Body [callback body, magic vars and custom vars are supported]
23
-    public $callbackBodyType;                       // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
-    public $returnUrl;                              // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
-    public $returnBody;                             // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
-    public $mediaEncode;                            // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
14
+	/*如下属性是可选的[The following attributes are optional]*/
15
+	public $detectMime = Conf::DETECT_MIME_TRUE;                             // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
+	public $dir;                                    // 路径[media file dir, magic vars and custom vars are supported]
17
+	public $name;                                   // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
+	public $sizeLimit;                              // 文件大小限制[upload size limited, in bytes]
19
+	public $mimeLimit;                              // 文件类型限制[upload mime type limited]
20
+	public $callbackUrl;                            // 回调URL [callback urls, ip address is recommended]
21
+	public $callbackHost;                           // 回调时Host [callback host]
22
+	public $callbackBody;                           // 回调时Body [callback body, magic vars and custom vars are supported]
23
+	public $callbackBodyType;                       // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
+	public $returnUrl;                              // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
+	public $returnBody;                             // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
+	public $mediaEncode;                            // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
27 27
 
28
-    public function __construct($option)
29
-    {
30
-        if (!isset($option['expiration']) || !$option['expiration']) {
31
-            $option['expiration'] = -1;
32
-        }
28
+	public function __construct($option)
29
+	{
30
+		if (!isset($option['expiration']) || !$option['expiration']) {
31
+			$option['expiration'] = -1;
32
+		}
33 33
 
34
-        foreach ($option as $attribute => $value) {
35
-            $this->{$attribute} = $value;
36
-        }
37
-    }
34
+		foreach ($option as $attribute => $value) {
35
+			$this->{$attribute} = $value;
36
+		}
37
+	}
38 38
 
39
-    public function toArray()
40
-    {
41
-        return (array) $this;
42
-        $array = [];
43
-        foreach ($this as $attribute => $value) {
44
-            if ($value !== null) {
45
-                $array[$attribute] = $value;
46
-            }
47
-        }
39
+	public function toArray()
40
+	{
41
+		return (array) $this;
42
+		$array = [];
43
+		foreach ($this as $attribute => $value) {
44
+			if ($value !== null) {
45
+				$array[$attribute] = $value;
46
+			}
47
+		}
48 48
 
49
-        return $array;
50
-    }
49
+		return $array;
50
+	}
51 51
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,24 +6,24 @@
 block discarded – undo
6 6
 class UploadPolicy
7 7
 {
8 8
     /*如下属性是必须的[The following attributes are required]*/
9
-    public $namespace;                              // 多媒体服务的空间名[media namespace name]
10
-    public $bucket;                                 // OSS的空间名[media bucket name]
11
-    public $insertOnly;                             // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
-    public $expiration;                             // 过期时间[expiration time, unix time, in milliseconds]
9
+    public $namespace; // 多媒体服务的空间名[media namespace name]
10
+    public $bucket; // OSS的空间名[media bucket name]
11
+    public $insertOnly; // 是否可覆盖[upload mode. it's not allowd uploading the same name files]
12
+    public $expiration; // 过期时间[expiration time, unix time, in milliseconds]
13 13
 
14 14
     /*如下属性是可选的[The following attributes are optional]*/
15
-    public $detectMime = Conf::DETECT_MIME_TRUE;                             // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
-    public $dir;                                    // 路径[media file dir, magic vars and custom vars are supported]
17
-    public $name;                                   // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
-    public $sizeLimit;                              // 文件大小限制[upload size limited, in bytes]
19
-    public $mimeLimit;                              // 文件类型限制[upload mime type limited]
20
-    public $callbackUrl;                            // 回调URL [callback urls, ip address is recommended]
21
-    public $callbackHost;                           // 回调时Host [callback host]
22
-    public $callbackBody;                           // 回调时Body [callback body, magic vars and custom vars are supported]
23
-    public $callbackBodyType;                       // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
-    public $returnUrl;                              // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
-    public $returnBody;                             // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
-    public $mediaEncode;                            // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
15
+    public $detectMime = Conf::DETECT_MIME_TRUE; // 是否进行类型检测[is auto detecte media file mime type, default is true]
16
+    public $dir; // 路径[media file dir, magic vars and custom vars are supported]
17
+    public $name; // 上传到服务端的文件名[media file name, magic vars and custom vars are supported]
18
+    public $sizeLimit; // 文件大小限制[upload size limited, in bytes]
19
+    public $mimeLimit; // 文件类型限制[upload mime type limited]
20
+    public $callbackUrl; // 回调URL [callback urls, ip address is recommended]
21
+    public $callbackHost; // 回调时Host [callback host]
22
+    public $callbackBody; // 回调时Body [callback body, magic vars and custom vars are supported]
23
+    public $callbackBodyType; // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8']
24
+    public $returnUrl; // 上传完成之后,303跳转的Url [return url, when return code is 303]
25
+    public $returnBody; // 上传完成返回体 [return body, magic vars and custom vars are supported]
26
+    public $mediaEncode; // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string]
27 27
 
28 28
     public function __construct($option)
29 29
     {
Please login to merge, or discard this patch.
sdk/Utils/ManageOption.php 2 patches
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -4,192 +4,192 @@
 block discarded – undo
4 4
 /**管理时的选项*/
5 5
 final class ManageOption extends ResourceInfo
6 6
 {
7
-    /*以下属性是”获取资源列表"方法所需的属性。即listFiles()、listDirs()方法中的参数 */
8
-    private $currentPage;                            //当前页号
9
-    private $pageSize;                               //每页的大小
10
-    /* 以下属性是"扫描黄图和广告图"方法所需的属性。即scanPorn()和scanAdvertising方法中的参数 */
11
-    private $filesArray;
12
-    private $urlsArray;
13
-    /* 以下属性是"鉴黄反馈"方法所需的属性。即pornFeedback()方法中的参数 */
14
-    private $pornFbArray;
15
-    /**
16
-     * UploadPolicy的构造函数
17
-     */
18
-    public function __construct($namespace = null)
19
-    {
20
-        $this->namespace = $namespace;
21
-        $this->currentPage = 1;
22
-        $this->pageSize = 10;
23
-    }
7
+	/*以下属性是”获取资源列表"方法所需的属性。即listFiles()、listDirs()方法中的参数 */
8
+	private $currentPage;                            //当前页号
9
+	private $pageSize;                               //每页的大小
10
+	/* 以下属性是"扫描黄图和广告图"方法所需的属性。即scanPorn()和scanAdvertising方法中的参数 */
11
+	private $filesArray;
12
+	private $urlsArray;
13
+	/* 以下属性是"鉴黄反馈"方法所需的属性。即pornFeedback()方法中的参数 */
14
+	private $pornFbArray;
15
+	/**
16
+	 * UploadPolicy的构造函数
17
+	 */
18
+	public function __construct($namespace = null)
19
+	{
20
+		$this->namespace = $namespace;
21
+		$this->currentPage = 1;
22
+		$this->pageSize = 10;
23
+	}
24 24
 
25
-    /**
26
-     * 生成文件列表listFiles()方法所需的参数
27
-     */
28
-    public function buildListFilesParas()
29
-    {
30
-        return "namespace=" . $this->namespace . "&dir=" . urlencode($this->dir) .
31
-            "&currentPage=" . $this->currentPage . "&pageSize=" . $this->pageSize;
32
-    }
25
+	/**
26
+	 * 生成文件列表listFiles()方法所需的参数
27
+	 */
28
+	public function buildListFilesParas()
29
+	{
30
+		return "namespace=" . $this->namespace . "&dir=" . urlencode($this->dir) .
31
+			"&currentPage=" . $this->currentPage . "&pageSize=" . $this->pageSize;
32
+	}
33 33
 
34
-    /**
35
-     * 校验待检测资源信息是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $bodyArray}
36
-     */
37
-    public function checkFilesAndUrls()
38
-    {
39
-        if (empty($this->filesArray) && empty($this->urlsArray)) {
40
-            return array(false, "resource's info is empty"); //待检测资源不能均为空,反馈错误
41
-        } elseif (!empty($this->filesArray) && !empty($this->urlsArray)) {
42
-            return array(false, "resource and url could not exist all at once"); //均存在时,反馈错误
43
-        }
44
-        $bodyArray = array();
45
-        $resourceStr = '';
46
-        if (!empty($this->filesArray)) {
47
-            //检测文件是否合法。若合法则返回http请求体所需参数
48
-            foreach ($this->filesArray as $resourceInfo) {
49
-                list($valid, $msg) = $resourceInfo->checkResourceInfo(true, true); //检测文件信息是否合法
50
-                if (!$valid) {
51
-                    return array($valid, $msg);
52
-                }
53
-                $resourceStr .= (empty($resourceStr) ? null : ';');
54
-                $resourceStr .= $resourceInfo->buildResourceId();
55
-            }
56
-            $bodyArray['resourceId'] = $resourceStr;
57
-        } elseif (!empty($this->urlsArray)) {
58
-            //检测URL是否合法。若合法则返回http请求体所需参数
59
-            foreach ($this->urlsArray as $url) {
60
-                if (empty($url)) {
61
-                    return array(false, "url's info is invalid");
62
-                }
63
-                $resourceStr .= (empty($resourceStr) ? null : ';');
64
-                $resourceStr .= $this->urlencode_ch($url);
65
-            }
66
-            $bodyArray['url'] = $resourceStr;
67
-        }
68
-        return array(true, 'valid', $bodyArray);
69
-    }
34
+	/**
35
+	 * 校验待检测资源信息是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $bodyArray}
36
+	 */
37
+	public function checkFilesAndUrls()
38
+	{
39
+		if (empty($this->filesArray) && empty($this->urlsArray)) {
40
+			return array(false, "resource's info is empty"); //待检测资源不能均为空,反馈错误
41
+		} elseif (!empty($this->filesArray) && !empty($this->urlsArray)) {
42
+			return array(false, "resource and url could not exist all at once"); //均存在时,反馈错误
43
+		}
44
+		$bodyArray = array();
45
+		$resourceStr = '';
46
+		if (!empty($this->filesArray)) {
47
+			//检测文件是否合法。若合法则返回http请求体所需参数
48
+			foreach ($this->filesArray as $resourceInfo) {
49
+				list($valid, $msg) = $resourceInfo->checkResourceInfo(true, true); //检测文件信息是否合法
50
+				if (!$valid) {
51
+					return array($valid, $msg);
52
+				}
53
+				$resourceStr .= (empty($resourceStr) ? null : ';');
54
+				$resourceStr .= $resourceInfo->buildResourceId();
55
+			}
56
+			$bodyArray['resourceId'] = $resourceStr;
57
+		} elseif (!empty($this->urlsArray)) {
58
+			//检测URL是否合法。若合法则返回http请求体所需参数
59
+			foreach ($this->urlsArray as $url) {
60
+				if (empty($url)) {
61
+					return array(false, "url's info is invalid");
62
+				}
63
+				$resourceStr .= (empty($resourceStr) ? null : ';');
64
+				$resourceStr .= $this->urlencode_ch($url);
65
+			}
66
+			$bodyArray['url'] = $resourceStr;
67
+		}
68
+		return array(true, 'valid', $bodyArray);
69
+	}
70 70
 
71
-    /**
72
-     * 生成扫描黄图scanPorn()方法所需的参数
73
-     */
74
-    public function buildScanPornParas()
75
-    {
76
-        $bodyArray = array();
77
-        if (!empty($this->filesArray)) {
78
-            $resourceStr = '';
79
-            foreach ($this->filesArray as $resourceInfo) {
80
-                $resourceStr .= (empty($resourceStr) ? null : ';');
81
-                $resourceStr .= $resourceInfo->buildResourceId();
82
-            }
83
-            $bodyArray['resourceId'] = $resourceStr;
84
-        } elseif (!empty($this->urlsArray)) {
85
-            $urlStr = '';
86
-            foreach ($this->urlsArray as $url) {
87
-                $urlStr .= (empty($urlStr) ? null : ';');
88
-                $urlStr .= urlencode($url);
89
-            }
90
-            $bodyArray['url'] = $urlStr;
91
-        }
92
-        return $bodyArray;
93
-    }
71
+	/**
72
+	 * 生成扫描黄图scanPorn()方法所需的参数
73
+	 */
74
+	public function buildScanPornParas()
75
+	{
76
+		$bodyArray = array();
77
+		if (!empty($this->filesArray)) {
78
+			$resourceStr = '';
79
+			foreach ($this->filesArray as $resourceInfo) {
80
+				$resourceStr .= (empty($resourceStr) ? null : ';');
81
+				$resourceStr .= $resourceInfo->buildResourceId();
82
+			}
83
+			$bodyArray['resourceId'] = $resourceStr;
84
+		} elseif (!empty($this->urlsArray)) {
85
+			$urlStr = '';
86
+			foreach ($this->urlsArray as $url) {
87
+				$urlStr .= (empty($urlStr) ? null : ';');
88
+				$urlStr .= urlencode($url);
89
+			}
90
+			$bodyArray['url'] = $urlStr;
91
+		}
92
+		return $bodyArray;
93
+	}
94 94
 
95
-    /**
96
-     * 生成扫描广告图scanAdvertising()方法所需的参数
97
-     */
98
-    public function buildScanAdvertisingParas()
99
-    {
100
-        return $this->buildScanPornParas();
101
-    }
95
+	/**
96
+	 * 生成扫描广告图scanAdvertising()方法所需的参数
97
+	 */
98
+	public function buildScanAdvertisingParas()
99
+	{
100
+		return $this->buildScanPornParas();
101
+	}
102 102
 
103
-    /**
104
-     * 校验鉴黄反馈信息是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $httpBody}
105
-     */
106
-    public function checkPornFeedbackInfos()
107
-    {
108
-        $httpBody = '';
109
-        if (empty($this->pornFbArray)) {
110
-            return array(false, "porn feedback info is empty", null); //鉴黄反馈信息为空,反馈错误
111
-        }
112
-        foreach ($this->pornFbArray as $pornFbInfo) {
113
-            $resourceInfo = $pornFbInfo['file']; //图片信息
114
-            list($valid, $msg) = $resourceInfo->checkResourceInfo(true, true); //检测图片信息是否合法
115
-            if (!$valid) {
116
-                return array($valid, $msg, null);
117
-            }
118
-            $type = $pornFbInfo['type'];
119
-            $wrong = $pornFbInfo['wrong'];
120
-            if (!isset($type) || ($type != 0 && $type != 1) || !is_bool($wrong)) {
121
-                return array(false, "parameters 'type' or 'wrong' is invalid", null); //参数type取值0、1, wrong是bool类型
122
-            }
123
-            $score = $pornFbInfo['score'];
124
-            if ($wrong && (!isset($score) || $score < 0 || $score > 1)) {
125
-                return array(false, "parameters 'score' is invalid", null); //当"wrong"=true时,参数score必须有,且取值范围为[0,1]
126
-            }
127
-            $pornFbInfo['file'] = $resourceInfo->toArray(); //将图片信息对象,转换为数组,并保存
128
-            $httpBody .= (empty($httpBody) ? null : '&'); //添加分隔符
129
-            $httpBody .= "feedback=" . urlencode(json_encode($pornFbInfo, true)); //urlencode编码
130
-        }
131
-        return array(true, "valid", $httpBody); //鉴黄反馈信息合法,并返回http请求体
132
-    }
133
-    /*###################下面是属性的get和set方法###############*/
134
-    /**设置当前页号*/
135
-    public function setCurrentPage($currentPage)
136
-    {
137
-        $this->currentPage = $currentPage;
138
-        return $this;
139
-    }
103
+	/**
104
+	 * 校验鉴黄反馈信息是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $httpBody}
105
+	 */
106
+	public function checkPornFeedbackInfos()
107
+	{
108
+		$httpBody = '';
109
+		if (empty($this->pornFbArray)) {
110
+			return array(false, "porn feedback info is empty", null); //鉴黄反馈信息为空,反馈错误
111
+		}
112
+		foreach ($this->pornFbArray as $pornFbInfo) {
113
+			$resourceInfo = $pornFbInfo['file']; //图片信息
114
+			list($valid, $msg) = $resourceInfo->checkResourceInfo(true, true); //检测图片信息是否合法
115
+			if (!$valid) {
116
+				return array($valid, $msg, null);
117
+			}
118
+			$type = $pornFbInfo['type'];
119
+			$wrong = $pornFbInfo['wrong'];
120
+			if (!isset($type) || ($type != 0 && $type != 1) || !is_bool($wrong)) {
121
+				return array(false, "parameters 'type' or 'wrong' is invalid", null); //参数type取值0、1, wrong是bool类型
122
+			}
123
+			$score = $pornFbInfo['score'];
124
+			if ($wrong && (!isset($score) || $score < 0 || $score > 1)) {
125
+				return array(false, "parameters 'score' is invalid", null); //当"wrong"=true时,参数score必须有,且取值范围为[0,1]
126
+			}
127
+			$pornFbInfo['file'] = $resourceInfo->toArray(); //将图片信息对象,转换为数组,并保存
128
+			$httpBody .= (empty($httpBody) ? null : '&'); //添加分隔符
129
+			$httpBody .= "feedback=" . urlencode(json_encode($pornFbInfo, true)); //urlencode编码
130
+		}
131
+		return array(true, "valid", $httpBody); //鉴黄反馈信息合法,并返回http请求体
132
+	}
133
+	/*###################下面是属性的get和set方法###############*/
134
+	/**设置当前页号*/
135
+	public function setCurrentPage($currentPage)
136
+	{
137
+		$this->currentPage = $currentPage;
138
+		return $this;
139
+	}
140 140
 
141
-    /**
142
-     * 设置每页的大小
143
-     */
144
-    public function setPageSize($pageSize)
145
-    {
146
-        $this->pageSize = $pageSize;
147
-        return $this;
148
-    }
141
+	/**
142
+	 * 设置每页的大小
143
+	 */
144
+	public function setPageSize($pageSize)
145
+	{
146
+		$this->pageSize = $pageSize;
147
+		return $this;
148
+	}
149 149
 
150
-    /**
151
-     * 添加待扫描文件信息。
152
-     */
153
-    public function addResource($namespace = null, $dir = null, $name = null)
154
-    {
155
-        if (!isset($this->filesArray)) {
156
-            $this->filesArray = array();
157
-        }
158
-        array_push($this->filesArray, new ResourceInfo($namespace, $dir, $name));
159
-    }
150
+	/**
151
+	 * 添加待扫描文件信息。
152
+	 */
153
+	public function addResource($namespace = null, $dir = null, $name = null)
154
+	{
155
+		if (!isset($this->filesArray)) {
156
+			$this->filesArray = array();
157
+		}
158
+		array_push($this->filesArray, new ResourceInfo($namespace, $dir, $name));
159
+	}
160 160
 
161
-    /**
162
-     * 添加待扫描URL信息。
163
-     */
164
-    public function addUrl($url)
165
-    {
166
-        if (!isset($this->urlsArray)) {
167
-            $this->urlsArray = array();
168
-        }
169
-        array_push($this->urlsArray, $url);
170
-    }
161
+	/**
162
+	 * 添加待扫描URL信息。
163
+	 */
164
+	public function addUrl($url)
165
+	{
166
+		if (!isset($this->urlsArray)) {
167
+			$this->urlsArray = array();
168
+		}
169
+		array_push($this->urlsArray, $url);
170
+	}
171 171
 
172
-    /**
173
-     * 添加鉴黄反馈信息。
174
-     * @param string $namespace 空间名[必须]。
175
-     * @param string $dir 路径。为空则默认根目录
176
-     * @param string $name 文件名。不能为空
177
-     * @param bool $type 黄图类型[必须]。0或者1,0是非黄图,1是黄图
178
-     * @param bool $wrong 鉴黄判断[必须]。true代表用户认为多媒体鉴黄服务的结果有问题。当为true的时候必须传score
179
-     * @param float $score 黄图分值。[可选]取值范围[0-1],值越高则是黄图可能性越高
180
-     */
181
-    public function addPornFbInfo($namespace = null, $dir = null, $name = null, $type = null, $wrong = null, $score = null)
182
-    {
183
-        if (!isset($this->pornFbArray)) {
184
-            $this->pornFbArray = array();
185
-        }
186
-        $pornFbInfo = array(
187
-            "file" => new ResourceInfo($namespace, $dir, $name),
188
-            "type" => $type, "wrong" => $wrong
189
-        );
190
-        if ($wrong) {
191
-            $pornFbInfo['score'] = $score; //当$wrong为true的时候必须传score
192
-        }
193
-        array_push($this->pornFbArray, $pornFbInfo);
194
-    }
172
+	/**
173
+	 * 添加鉴黄反馈信息。
174
+	 * @param string $namespace 空间名[必须]。
175
+	 * @param string $dir 路径。为空则默认根目录
176
+	 * @param string $name 文件名。不能为空
177
+	 * @param bool $type 黄图类型[必须]。0或者1,0是非黄图,1是黄图
178
+	 * @param bool $wrong 鉴黄判断[必须]。true代表用户认为多媒体鉴黄服务的结果有问题。当为true的时候必须传score
179
+	 * @param float $score 黄图分值。[可选]取值范围[0-1],值越高则是黄图可能性越高
180
+	 */
181
+	public function addPornFbInfo($namespace = null, $dir = null, $name = null, $type = null, $wrong = null, $score = null)
182
+	{
183
+		if (!isset($this->pornFbArray)) {
184
+			$this->pornFbArray = array();
185
+		}
186
+		$pornFbInfo = array(
187
+			"file" => new ResourceInfo($namespace, $dir, $name),
188
+			"type" => $type, "wrong" => $wrong
189
+		);
190
+		if ($wrong) {
191
+			$pornFbInfo['score'] = $score; //当$wrong为true的时候必须传score
192
+		}
193
+		array_push($this->pornFbArray, $pornFbInfo);
194
+	}
195 195
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 final class ManageOption extends ResourceInfo
6 6
 {
7 7
     /*以下属性是”获取资源列表"方法所需的属性。即listFiles()、listDirs()方法中的参数 */
8
-    private $currentPage;                            //当前页号
9
-    private $pageSize;                               //每页的大小
8
+    private $currentPage; //当前页号
9
+    private $pageSize; //每页的大小
10 10
     /* 以下属性是"扫描黄图和广告图"方法所需的属性。即scanPorn()和scanAdvertising方法中的参数 */
11 11
     private $filesArray;
12 12
     private $urlsArray;
Please login to merge, or discard this patch.
sdk/Conf/Conf.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -3,39 +3,39 @@
 block discarded – undo
3 3
 
4 4
 class Conf
5 5
 {
6
-    const CHARSET = "UTF-8";
7
-    const SDK_VERSION = '2.0.3';
6
+	const CHARSET = "UTF-8";
7
+	const SDK_VERSION = '2.0.3';
8 8
 
9
-    const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com";        //文件上传的地址
10
-    const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com";            //服务管理的地址
11
-    const MANAGE_API_VERSION = "3.0";        //资源管理接口版本
12
-    const SCAN_PORN_VERSION = "3.1";        //黄图扫描接口版本
13
-    const MEDIA_ENCODE_VERSION = "3.0";        //媒体转码接口版本
9
+	const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com";        //文件上传的地址
10
+	const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com";            //服务管理的地址
11
+	const MANAGE_API_VERSION = "3.0";        //资源管理接口版本
12
+	const SCAN_PORN_VERSION = "3.1";        //黄图扫描接口版本
13
+	const MEDIA_ENCODE_VERSION = "3.0";        //媒体转码接口版本
14 14
 
15
-    const UPLOAD_API_UPLOAD = "/api/proxy/upload";
16
-    const UPLOAD_API_BLOCK_INIT = "/api/proxy/blockInit";
17
-    const UPLOAD_API_BLOCK_UPLOAD = "/api/proxy/blockUpload";
18
-    const UPLOAD_API_BLOCK_COMPLETE = "/api/proxy/blockComplete";
19
-    const UPLOAD_API_BLOCK_CANCEL = "/api/proxy/blockCancel";
15
+	const UPLOAD_API_UPLOAD = "/api/proxy/upload";
16
+	const UPLOAD_API_BLOCK_INIT = "/api/proxy/blockInit";
17
+	const UPLOAD_API_BLOCK_UPLOAD = "/api/proxy/blockUpload";
18
+	const UPLOAD_API_BLOCK_COMPLETE = "/api/proxy/blockComplete";
19
+	const UPLOAD_API_BLOCK_CANCEL = "/api/proxy/blockCancel";
20 20
 
21
-    const TYPE_TOP = "TOP";
22
-    const TYPE_CLOUD = "CLOUD";
21
+	const TYPE_TOP = "TOP";
22
+	const TYPE_CLOUD = "CLOUD";
23 23
 
24
-    const DETECT_MIME_TRUE = 1;            //检测MimeType
25
-    const DETECT_MIME_NONE = 0;            //不检测MimeType
26
-    const INSERT_ONLY_TRUE = 1;            //文件上传不可覆盖
27
-    const INSERT_ONLY_NONE = 0;            //文件上传可覆盖
24
+	const DETECT_MIME_TRUE = 1;            //检测MimeType
25
+	const DETECT_MIME_NONE = 0;            //不检测MimeType
26
+	const INSERT_ONLY_TRUE = 1;            //文件上传不可覆盖
27
+	const INSERT_ONLY_NONE = 0;            //文件上传可覆盖
28 28
 
29
-    const MIN_OBJ_SIZE = 1;        //1024*100;
30
-    const HTTP_TIMEOUT = 30;            //http的超时时间:30s
31
-    const HTTP_RETRY = 1;                //http失败后重试:1
29
+	const MIN_OBJ_SIZE = 1;        //1024*100;
30
+	const HTTP_TIMEOUT = 30;            //http的超时时间:30s
31
+	const HTTP_RETRY = 1;                //http失败后重试:1
32 32
 
33
-    const BLOCK_MIN_SIZE = 102400;        //文件分片最小值:1024*100; 100K
34
-    const BLOCK_DEFF_SIZE = 209715200;    //文件分片默认值:1024*1024*2; 2M
35
-    const BLOCK_MAX_SIZE = 104857600;    //文件分片最大值:1024*1024*10; 10M
33
+	const BLOCK_MIN_SIZE = 102400;        //文件分片最小值:1024*100; 100K
34
+	const BLOCK_DEFF_SIZE = 209715200;    //文件分片默认值:1024*1024*2; 2M
35
+	const BLOCK_MAX_SIZE = 104857600;    //文件分片最大值:1024*1024*10; 10M
36 36
 
37
-    const CURL_ERR_LOG = "curl_error.log";    //curl请求时的错误日志信息
37
+	const CURL_ERR_LOG = "curl_error.log";    //curl请求时的错误日志信息
38 38
 
39
-    const RUN_LEVEL_RELEASE = 1;        //release级别
40
-    const RUN_LEVEL_DEBUG = 2;            //debug级别
39
+	const RUN_LEVEL_RELEASE = 1;        //release级别
40
+	const RUN_LEVEL_DEBUG = 2;            //debug级别
41 41
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,11 +6,11 @@  discard block
 block discarded – undo
6 6
     const CHARSET = "UTF-8";
7 7
     const SDK_VERSION = '2.0.3';
8 8
 
9
-    const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com";        //文件上传的地址
10
-    const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com";            //服务管理的地址
11
-    const MANAGE_API_VERSION = "3.0";        //资源管理接口版本
12
-    const SCAN_PORN_VERSION = "3.1";        //黄图扫描接口版本
13
-    const MEDIA_ENCODE_VERSION = "3.0";        //媒体转码接口版本
9
+    const UPLOAD_HOST_MEDIA = "https://upload.media.aliyun.com"; //文件上传的地址
10
+    const MANAGE_HOST_MEDIA = "https://rs.media.aliyun.com"; //服务管理的地址
11
+    const MANAGE_API_VERSION = "3.0"; //资源管理接口版本
12
+    const SCAN_PORN_VERSION = "3.1"; //黄图扫描接口版本
13
+    const MEDIA_ENCODE_VERSION = "3.0"; //媒体转码接口版本
14 14
 
15 15
     const UPLOAD_API_UPLOAD = "/api/proxy/upload";
16 16
     const UPLOAD_API_BLOCK_INIT = "/api/proxy/blockInit";
@@ -21,21 +21,21 @@  discard block
 block discarded – undo
21 21
     const TYPE_TOP = "TOP";
22 22
     const TYPE_CLOUD = "CLOUD";
23 23
 
24
-    const DETECT_MIME_TRUE = 1;            //检测MimeType
25
-    const DETECT_MIME_NONE = 0;            //不检测MimeType
26
-    const INSERT_ONLY_TRUE = 1;            //文件上传不可覆盖
27
-    const INSERT_ONLY_NONE = 0;            //文件上传可覆盖
24
+    const DETECT_MIME_TRUE = 1; //检测MimeType
25
+    const DETECT_MIME_NONE = 0; //不检测MimeType
26
+    const INSERT_ONLY_TRUE = 1; //文件上传不可覆盖
27
+    const INSERT_ONLY_NONE = 0; //文件上传可覆盖
28 28
 
29
-    const MIN_OBJ_SIZE = 1;        //1024*100;
30
-    const HTTP_TIMEOUT = 30;            //http的超时时间:30s
31
-    const HTTP_RETRY = 1;                //http失败后重试:1
29
+    const MIN_OBJ_SIZE = 1; //1024*100;
30
+    const HTTP_TIMEOUT = 30; //http的超时时间:30s
31
+    const HTTP_RETRY = 1; //http失败后重试:1
32 32
 
33
-    const BLOCK_MIN_SIZE = 102400;        //文件分片最小值:1024*100; 100K
34
-    const BLOCK_DEFF_SIZE = 209715200;    //文件分片默认值:1024*1024*2; 2M
35
-    const BLOCK_MAX_SIZE = 104857600;    //文件分片最大值:1024*1024*10; 10M
33
+    const BLOCK_MIN_SIZE = 102400; //文件分片最小值:1024*100; 100K
34
+    const BLOCK_DEFF_SIZE = 209715200; //文件分片默认值:1024*1024*2; 2M
35
+    const BLOCK_MAX_SIZE = 104857600; //文件分片最大值:1024*1024*10; 10M
36 36
 
37
-    const CURL_ERR_LOG = "curl_error.log";    //curl请求时的错误日志信息
37
+    const CURL_ERR_LOG = "curl_error.log"; //curl请求时的错误日志信息
38 38
 
39
-    const RUN_LEVEL_RELEASE = 1;        //release级别
40
-    const RUN_LEVEL_DEBUG = 2;            //debug级别
39
+    const RUN_LEVEL_RELEASE = 1; //release级别
40
+    const RUN_LEVEL_DEBUG = 2; //debug级别
41 41
 }
Please login to merge, or discard this patch.
sdk/Core/UploadClient.php 2 patches
Indentation   +541 added lines, -541 removed lines patch added patch discarded remove patch
@@ -11,128 +11,128 @@  discard block
 block discarded – undo
11 11
 
12 12
 class UploadClient
13 13
 {
14
-    private $upload_host;
15
-    private $ak;
16
-    private $sk;
17
-    private $type; // "CLOUD" or "TOP";
14
+	private $upload_host;
15
+	private $ak;
16
+	private $sk;
17
+	private $type; // "CLOUD" or "TOP";
18 18
 
19
-    public function __construct($ak, $sk, $type = Conf::TYPE_TOP)
20
-    {
21
-        $this->ak = $ak;
22
-        $this->sk = $sk;
23
-        $this->type = $type;
24
-        $this->upload_host = Conf::UPLOAD_HOST_MEDIA;
25
-    }
19
+	public function __construct($ak, $sk, $type = Conf::TYPE_TOP)
20
+	{
21
+		$this->ak = $ak;
22
+		$this->sk = $sk;
23
+		$this->type = $type;
24
+		$this->upload_host = Conf::UPLOAD_HOST_MEDIA;
25
+	}
26 26
 
27
-    /**
28
-     * 上传文件。根据文件大小判断是否进行分片
29
-     * @param string $filePath  文件路径
30
-     * @param UploadPolicy $uploadPolicy    上传策略
31
-     * @param UploadOption $uploadOption    上传选项
32
-     * @return array
33
-     */
34
-    public function upload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
35
-    {
36
-        $encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
37
-        if (!file_exists($encodePath)) {
38
-            return $this->_errorResponse("FileNotExist", "file not exist");
39
-        }
40
-        if (empty($uploadOption)) {
41
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
42
-        }
43
-        if (empty($uploadOption->name)) {
44
-            $uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
45
-        }
46
-        // UploadPolicy 和 UploadOption检查
47
-        list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
48
-        if (!$isValid) {
49
-            return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
50
-        }
51
-        $fileSize = filesize($encodePath);
52
-        // 文件大于设定的分片大小(默认2M),则进行分片上传uploadSuperfile()
53
-        if ($fileSize > ($uploadOption->blockSize)) {
54
-            return $this->uploadSuperFile($encodePath, $uploadPolicy, $uploadOption);
55
-        }
56
-        // 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile()
57
-        return $this->uploadMiniFile($encodePath, $uploadPolicy, $uploadOption);
58
-    }
27
+	/**
28
+	 * 上传文件。根据文件大小判断是否进行分片
29
+	 * @param string $filePath  文件路径
30
+	 * @param UploadPolicy $uploadPolicy    上传策略
31
+	 * @param UploadOption $uploadOption    上传选项
32
+	 * @return array
33
+	 */
34
+	public function upload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
35
+	{
36
+		$encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
37
+		if (!file_exists($encodePath)) {
38
+			return $this->_errorResponse("FileNotExist", "file not exist");
39
+		}
40
+		if (empty($uploadOption)) {
41
+			$uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
42
+		}
43
+		if (empty($uploadOption->name)) {
44
+			$uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
45
+		}
46
+		// UploadPolicy 和 UploadOption检查
47
+		list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
48
+		if (!$isValid) {
49
+			return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
50
+		}
51
+		$fileSize = filesize($encodePath);
52
+		// 文件大于设定的分片大小(默认2M),则进行分片上传uploadSuperfile()
53
+		if ($fileSize > ($uploadOption->blockSize)) {
54
+			return $this->uploadSuperFile($encodePath, $uploadPolicy, $uploadOption);
55
+		}
56
+		// 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile()
57
+		return $this->uploadMiniFile($encodePath, $uploadPolicy, $uploadOption);
58
+	}
59 59
 
60
-    /**
61
-     * 上传小文件
62
-     * @param string $filePath 文件路径
63
-     * @param UploadPolicy $uploadPolicy 上传策略
64
-     * @param UploadOption $uploadOption 上传选项
65
-     * @return array
66
-     */
67
-    protected function uploadMiniFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
68
-    {
69
-        $data = file_get_contents($filePath);
70
-        $uploadOption->setContent($data);
71
-        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
72
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
73
-    }
60
+	/**
61
+	 * 上传小文件
62
+	 * @param string $filePath 文件路径
63
+	 * @param UploadPolicy $uploadPolicy 上传策略
64
+	 * @param UploadOption $uploadOption 上传选项
65
+	 * @return array
66
+	 */
67
+	protected function uploadMiniFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
68
+	{
69
+		$data = file_get_contents($filePath);
70
+		$uploadOption->setContent($data);
71
+		$url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
72
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
73
+	}
74 74
 
75
-    /**
76
-     * 分片上传大文件
77
-     * @param string $filePath 文件路径
78
-     * @param UploadPolicy $uploadPolicy 上传策略
79
-     * @param UploadOption $uploadOption 上传选项
80
-     * @return array
81
-     */
82
-    protected function uploadSuperFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
83
-    {
84
-        $fileSize = filesize($filePath);        // 文件大小
85
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
86
-        $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
87
-        for ($i = 0; $i < $blockNum; $i++) {
88
-            $currentSize = $blockSize; // 当前文件块的大小
89
-            if (($i + 1) === $blockNum) {
90
-                $currentSize = ($fileSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
91
-            }
92
-            $offset = $i * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
93
-            $blockData = file_get_contents($filePath, 0, null, $offset, $currentSize); //当前文件块的数据
94
-            $uploadOption->setContent($blockData); // 设置待上传的文件块
95
-            $httpRes = null;
96
-            if (0 == $i) {
97
-                // 分片初始化阶段
98
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
99
-                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
100
-                $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
101
-                $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
102
-                $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
103
-                $uploadOption->setUploadId($uploadId);
104
-                $uploadOption->setUniqueIdId($id);
105
-            } else {
106
-                // 分片上传过程中
107
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
108
-                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
109
-                $uploadOption->setPartNumber($i + 1);                           //
110
-                $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
111
-            }
112
-            // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
113
-            if (!$httpRes['isSuccess']) {
114
-                if ($uploadOption->checkMutipartParas()) {
115
-                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
116
-                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
117
-                    $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
118
-                }
119
-                return $httpRes;
120
-                //              $message = isset( $httpRes ['message'] ) ? $httpRes ['message'] : null;
121
-                //              $code = isset( $httpRes ['code'] ) ? $httpRes ['code'] : null;
122
-                //              $requestId = isset( $httpRes ['requestId'] ) ? $httpRes ['requestId'] : null;
123
-                //              return $this->_errorResponse ( $code, "fail upload block file:" . $message, $requestId );
124
-            }
125
-            // 保存 块编号partNumber 和 标记ETag,用于分片完成时的参数设置
126
-            $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
127
-        }
128
-        // 分片上传完成
129
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
130
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
131
-        $uploadOption->setMd5(md5_file($filePath));                         //文件Md5
132
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
133
-    }
75
+	/**
76
+	 * 分片上传大文件
77
+	 * @param string $filePath 文件路径
78
+	 * @param UploadPolicy $uploadPolicy 上传策略
79
+	 * @param UploadOption $uploadOption 上传选项
80
+	 * @return array
81
+	 */
82
+	protected function uploadSuperFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
83
+	{
84
+		$fileSize = filesize($filePath);        // 文件大小
85
+		$blockSize = $uploadOption->blockSize;  // 文件分片大小
86
+		$blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
87
+		for ($i = 0; $i < $blockNum; $i++) {
88
+			$currentSize = $blockSize; // 当前文件块的大小
89
+			if (($i + 1) === $blockNum) {
90
+				$currentSize = ($fileSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
91
+			}
92
+			$offset = $i * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
93
+			$blockData = file_get_contents($filePath, 0, null, $offset, $currentSize); //当前文件块的数据
94
+			$uploadOption->setContent($blockData); // 设置待上传的文件块
95
+			$httpRes = null;
96
+			if (0 == $i) {
97
+				// 分片初始化阶段
98
+				$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
99
+				$uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
100
+				$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
101
+				$uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
102
+				$id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
103
+				$uploadOption->setUploadId($uploadId);
104
+				$uploadOption->setUniqueIdId($id);
105
+			} else {
106
+				// 分片上传过程中
107
+				$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
108
+				$uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
109
+				$uploadOption->setPartNumber($i + 1);                           //
110
+				$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
111
+			}
112
+			// 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
113
+			if (!$httpRes['isSuccess']) {
114
+				if ($uploadOption->checkMutipartParas()) {
115
+					$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
116
+					$uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
117
+					$this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
118
+				}
119
+				return $httpRes;
120
+				//              $message = isset( $httpRes ['message'] ) ? $httpRes ['message'] : null;
121
+				//              $code = isset( $httpRes ['code'] ) ? $httpRes ['code'] : null;
122
+				//              $requestId = isset( $httpRes ['requestId'] ) ? $httpRes ['requestId'] : null;
123
+				//              return $this->_errorResponse ( $code, "fail upload block file:" . $message, $requestId );
124
+			}
125
+			// 保存 块编号partNumber 和 标记ETag,用于分片完成时的参数设置
126
+			$uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
127
+		}
128
+		// 分片上传完成
129
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
130
+		$uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
131
+		$uploadOption->setMd5(md5_file($filePath));                         //文件Md5
132
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
133
+	}
134 134
 
135
-    /**上传字符串/二进制数据
135
+	/**上传字符串/二进制数据
136 136
      * @param string $data
137 137
      *          文件数据
138 138
      * @param UploadPolicy $uploadPolicy
@@ -141,454 +141,454 @@  discard block
 block discarded – undo
141 141
      *          上传选项
142 142
      * @return array
143 143
      */
144
-    public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
145
-    {
146
-        if (empty($uploadOption)) {
147
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
148
-        }
149
-        // UploadPolicy 和 UploadOption检查
150
-        list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
151
-        if (!$isValid) {
152
-            return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
153
-        }
154
-        $dataSize = strlen($data);
155
-        // 文件大于设定的分片大小(默认2M),则进行分片上传uploadSuperfile()
156
-        if ($dataSize > ($uploadOption->blockSize)) {
157
-            return $this->uploadSuperData($data, $uploadPolicy, $uploadOption);
158
-        }
159
-        // 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile()
160
-        $uploadOption->setContent($data);
161
-        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
162
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
163
-    }
144
+	public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
145
+	{
146
+		if (empty($uploadOption)) {
147
+			$uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
148
+		}
149
+		// UploadPolicy 和 UploadOption检查
150
+		list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
151
+		if (!$isValid) {
152
+			return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
153
+		}
154
+		$dataSize = strlen($data);
155
+		// 文件大于设定的分片大小(默认2M),则进行分片上传uploadSuperfile()
156
+		if ($dataSize > ($uploadOption->blockSize)) {
157
+			return $this->uploadSuperData($data, $uploadPolicy, $uploadOption);
158
+		}
159
+		// 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile()
160
+		$uploadOption->setContent($data);
161
+		$url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
162
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
163
+	}
164 164
 
165
-    /**
166
-     * 分片上传大文件数据
167
-     * @param string $data 文件数据
168
-     * @param UploadPolicy $uploadPolicy 上传策略
169
-     * @param UploadOption $uploadOption 上传选项
170
-     * @return array
171
-     */
172
-    protected function uploadSuperData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
173
-    {
174
-        $dataSize = strlen($data);          // 文件大小
175
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
176
-        $blockNum = intval(ceil($dataSize / $blockSize)); // 文件分片后的块数
177
-        for ($i = 0; $i < $blockNum; $i++) {
178
-            $currentSize = $blockSize; // 当前文件块的大小
179
-            if (($i + 1) === $blockNum) {
180
-                $currentSize = ($dataSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
181
-            }
182
-            $offset = $i * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
183
-            $blockData = substr($data, $offset, $currentSize); //当前文件块的数据
184
-            $uploadOption->setContent($blockData); // 设置待上传的文件块
185
-            $httpRes = null;
186
-            if (0 == $i) {
187
-                // 分片初始化阶段
188
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
189
-                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
190
-                $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
191
-                $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
192
-                $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
193
-                $uploadOption->setUploadId($uploadId);
194
-                $uploadOption->setUniqueIdId($id);
195
-            } else {
196
-                // 分片上传过程中
197
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
198
-                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
199
-                $uploadOption->setPartNumber($i + 1);                           //
200
-                $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
201
-            }
202
-            // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
203
-            if (!$httpRes['isSuccess']) {
204
-                if ($uploadOption->checkMutipartParas()) {
205
-                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
206
-                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
207
-                    $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
208
-                }
209
-                return $httpRes;
210
-            }
211
-            // 保存 块编号partNumber 和 标记ETag,用于分片完成时的参数设置
212
-            $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
213
-        }
214
-        // 分片上传完成
215
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
216
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
217
-        $uploadOption->setMd5(md5($data));                          //文件Md5
218
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
219
-    }
165
+	/**
166
+	 * 分片上传大文件数据
167
+	 * @param string $data 文件数据
168
+	 * @param UploadPolicy $uploadPolicy 上传策略
169
+	 * @param UploadOption $uploadOption 上传选项
170
+	 * @return array
171
+	 */
172
+	protected function uploadSuperData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
173
+	{
174
+		$dataSize = strlen($data);          // 文件大小
175
+		$blockSize = $uploadOption->blockSize;  // 文件分片大小
176
+		$blockNum = intval(ceil($dataSize / $blockSize)); // 文件分片后的块数
177
+		for ($i = 0; $i < $blockNum; $i++) {
178
+			$currentSize = $blockSize; // 当前文件块的大小
179
+			if (($i + 1) === $blockNum) {
180
+				$currentSize = ($dataSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
181
+			}
182
+			$offset = $i * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
183
+			$blockData = substr($data, $offset, $currentSize); //当前文件块的数据
184
+			$uploadOption->setContent($blockData); // 设置待上传的文件块
185
+			$httpRes = null;
186
+			if (0 == $i) {
187
+				// 分片初始化阶段
188
+				$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
189
+				$uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
190
+				$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
191
+				$uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
192
+				$id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
193
+				$uploadOption->setUploadId($uploadId);
194
+				$uploadOption->setUniqueIdId($id);
195
+			} else {
196
+				// 分片上传过程中
197
+				$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
198
+				$uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
199
+				$uploadOption->setPartNumber($i + 1);                           //
200
+				$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
201
+			}
202
+			// 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
203
+			if (!$httpRes['isSuccess']) {
204
+				if ($uploadOption->checkMutipartParas()) {
205
+					$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
206
+					$uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
207
+					$this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
208
+				}
209
+				return $httpRes;
210
+			}
211
+			// 保存 块编号partNumber 和 标记ETag,用于分片完成时的参数设置
212
+			$uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
213
+		}
214
+		// 分片上传完成
215
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
216
+		$uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
217
+		$uploadOption->setMd5(md5($data));                          //文件Md5
218
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
219
+	}
220 220
 
221
-    /**
222
-     * 创建分片上传任务,指定待上传的文件。即初始化分片上传
223
-     * @param string $filePath 文件路径
224
-     * @param UploadPolicy $uploadPolicy 上传策略
225
-     * @param UploadOption $uploadOption 上传选项
226
-     * @return array 初始化分片上传的结果
227
-     */
228
-    public function multipartInit($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
229
-    {
230
-        $encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
231
-        if (!file_exists($encodePath)) {
232
-            return $this->_errorResponse("FileNotExist", "file not exist");
233
-        }
234
-        if (empty($uploadOption)) {
235
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
236
-        }
237
-        if (empty($uploadOption->name)) {
238
-            $uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
239
-        }
240
-        $blockData = file_get_contents($encodePath, 0, null, 0, $uploadOption->blockSize);
241
-        return $this->multipartInitByData($blockData, $uploadPolicy, $uploadOption);
242
-    }
221
+	/**
222
+	 * 创建分片上传任务,指定待上传的文件。即初始化分片上传
223
+	 * @param string $filePath 文件路径
224
+	 * @param UploadPolicy $uploadPolicy 上传策略
225
+	 * @param UploadOption $uploadOption 上传选项
226
+	 * @return array 初始化分片上传的结果
227
+	 */
228
+	public function multipartInit($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
229
+	{
230
+		$encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
231
+		if (!file_exists($encodePath)) {
232
+			return $this->_errorResponse("FileNotExist", "file not exist");
233
+		}
234
+		if (empty($uploadOption)) {
235
+			$uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
236
+		}
237
+		if (empty($uploadOption->name)) {
238
+			$uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
239
+		}
240
+		$blockData = file_get_contents($encodePath, 0, null, 0, $uploadOption->blockSize);
241
+		return $this->multipartInitByData($blockData, $uploadPolicy, $uploadOption);
242
+	}
243 243
 
244
-    /**
245
-     * 创建分片上传任务,指定初始化分片任务的数据,即第一块数据
246
-     * @param string $blockData 文件数据
247
-     * @param UploadPolicy $uploadPolicy 上传策略
248
-     * @param UploadOption $uploadOption 上传选项
249
-     * @return array 初始化分片上传的结果
250
-     */
251
-    public function multipartInitByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
252
-    {
253
-        if (empty($uploadOption)) {
254
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
255
-        }
256
-        // UploadPolicy 和 UploadOption检查
257
-        list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
258
-        if (!$isValid) {
259
-            return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
260
-        }
261
-        // 数据大小不等于设定的分片大小(默认2M),则无法完成初始化
262
-        $dataSize = strlen($blockData);         // 数据文件大小
263
-        if ($dataSize != ($uploadOption->blockSize)) {
264
-            return $this->_errorResponse("MultipartInitError", "UploadOption's blockSize is not equal to data's size");
265
-        }
266
-        $uploadOption->setContent($blockData); // 设置待上传的文件块
267
-        $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
268
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
269
-        $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
270
-        //若成功返回,则保存初始化成功的uploadId、id 以及 partNumber、eTag
271
-        $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
272
-        $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
273
-        $uploadOption->setUploadId($uploadId);
274
-        $uploadOption->setUniqueIdId($id);
275
-        if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) {
276
-            $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
277
-        }
278
-        return $httpRes;
279
-    }
244
+	/**
245
+	 * 创建分片上传任务,指定初始化分片任务的数据,即第一块数据
246
+	 * @param string $blockData 文件数据
247
+	 * @param UploadPolicy $uploadPolicy 上传策略
248
+	 * @param UploadOption $uploadOption 上传选项
249
+	 * @return array 初始化分片上传的结果
250
+	 */
251
+	public function multipartInitByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
252
+	{
253
+		if (empty($uploadOption)) {
254
+			$uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
255
+		}
256
+		// UploadPolicy 和 UploadOption检查
257
+		list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
258
+		if (!$isValid) {
259
+			return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
260
+		}
261
+		// 数据大小不等于设定的分片大小(默认2M),则无法完成初始化
262
+		$dataSize = strlen($blockData);         // 数据文件大小
263
+		if ($dataSize != ($uploadOption->blockSize)) {
264
+			return $this->_errorResponse("MultipartInitError", "UploadOption's blockSize is not equal to data's size");
265
+		}
266
+		$uploadOption->setContent($blockData); // 设置待上传的文件块
267
+		$uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
268
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
269
+		$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
270
+		//若成功返回,则保存初始化成功的uploadId、id 以及 partNumber、eTag
271
+		$uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
272
+		$id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
273
+		$uploadOption->setUploadId($uploadId);
274
+		$uploadOption->setUniqueIdId($id);
275
+		if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) {
276
+			$uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
277
+		}
278
+		return $httpRes;
279
+	}
280 280
 
281
-    /**分片上传,指定待上传的文件。需要指定UploadOption中文件块编号
281
+	/**分片上传,指定待上传的文件。需要指定UploadOption中文件块编号
282 282
      * @param string $filePath 文件路径
283 283
      * @param UploadPolicy $uploadPolicy 上传策略
284 284
      * @param UploadOption $uploadOption 上传选项
285 285
      * @return array 初始化分片上传的结果
286 286
      */
287
-    public function multipartUpload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
288
-    {
289
-        $encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
290
-        if (!file_exists($encodePath)) {
291
-            return $this->_errorResponse("FileNotExist", "file not exist");
292
-        }
293
-        $fileSize = filesize($encodePath);      // 文件大小
294
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
295
-        $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
296
-        $currentSize = $blockSize; // 当前文件块的大小
297
-        if ($uploadOption->getPartNumber() == $blockNum) {
298
-            $currentSize = ($fileSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
299
-        }
300
-        $offset = ($uploadOption->getPartNumber() - 1) * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
301
-        $blockData = file_get_contents($encodePath, 0, null, $offset, $currentSize);
302
-        return $this->multipartUploadByData($blockData, $uploadPolicy, $uploadOption);
303
-    }
287
+	public function multipartUpload($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
288
+	{
289
+		$encodePath = iconv('UTF-8', 'GB2312', $filePath); //中文需要转换成gb2312,file_exist等函数才能识别
290
+		if (!file_exists($encodePath)) {
291
+			return $this->_errorResponse("FileNotExist", "file not exist");
292
+		}
293
+		$fileSize = filesize($encodePath);      // 文件大小
294
+		$blockSize = $uploadOption->blockSize;  // 文件分片大小
295
+		$blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
296
+		$currentSize = $blockSize; // 当前文件块的大小
297
+		if ($uploadOption->getPartNumber() == $blockNum) {
298
+			$currentSize = ($fileSize - ($blockNum - 1) * $blockSize); // 计算最后一个块的大小
299
+		}
300
+		$offset = ($uploadOption->getPartNumber() - 1) * $blockSize; // 当前文件块相对于文件开头的偏移量(块的起始位置)
301
+		$blockData = file_get_contents($encodePath, 0, null, $offset, $currentSize);
302
+		return $this->multipartUploadByData($blockData, $uploadPolicy, $uploadOption);
303
+	}
304 304
 
305
-    /**
306
-     * 分片上传,指定待上传的数据。需要指定UploadOption中文件块编号
307
-     * @param string $filePath 文件路径
308
-     * @param UploadPolicy $uploadPolicy 上传策略
309
-     * @param UploadOption $uploadOption 上传选项
310
-     * @return array 分片上传的结果
311
-     */
312
-    public function multipartUploadByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
313
-    {
314
-        $partNumber = $uploadOption->getPartNumber(); //php 5.3的版本使用empty()传递函数返回值会报错。所以为了兼容,增加临时变量
315
-        // 检查分片上传所需的参数是否设置正确
316
-        if (!$uploadOption->checkMutipartParas() || empty($partNumber)) {
317
-            return $this->_errorResponse("MultipartUploadError", "multipart upload's parameters(id,uploadId,partNumber) error");
318
-        }
319
-        $uploadOption->setContent($blockData); // 设置待上传的文件块
320
-        $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
321
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
322
-        $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
323
-        if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) {
324
-            $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
325
-        }
326
-        return $httpRes;
327
-    }
305
+	/**
306
+	 * 分片上传,指定待上传的数据。需要指定UploadOption中文件块编号
307
+	 * @param string $filePath 文件路径
308
+	 * @param UploadPolicy $uploadPolicy 上传策略
309
+	 * @param UploadOption $uploadOption 上传选项
310
+	 * @return array 分片上传的结果
311
+	 */
312
+	public function multipartUploadByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
313
+	{
314
+		$partNumber = $uploadOption->getPartNumber(); //php 5.3的版本使用empty()传递函数返回值会报错。所以为了兼容,增加临时变量
315
+		// 检查分片上传所需的参数是否设置正确
316
+		if (!$uploadOption->checkMutipartParas() || empty($partNumber)) {
317
+			return $this->_errorResponse("MultipartUploadError", "multipart upload's parameters(id,uploadId,partNumber) error");
318
+		}
319
+		$uploadOption->setContent($blockData); // 设置待上传的文件块
320
+		$uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
321
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
322
+		$httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
323
+		if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) {
324
+			$uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
325
+		}
326
+		return $httpRes;
327
+	}
328 328
 
329
-    /**
330
-     * 完成分片上传任务。需要指定UploadOption中整个文件的md5值
331
-     * @param UploadPolicy $uploadPolicy 上传策略
332
-     * @param UploadOption $uploadOption 上传选项
333
-     * @return array 分片上传完成的结果
334
-     */
335
-    public function multipartComplete(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
336
-    {
329
+	/**
330
+	 * 完成分片上传任务。需要指定UploadOption中整个文件的md5值
331
+	 * @param UploadPolicy $uploadPolicy 上传策略
332
+	 * @param UploadOption $uploadOption 上传选项
333
+	 * @return array 分片上传完成的结果
334
+	 */
335
+	public function multipartComplete(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
336
+	{
337 337
  // 检查分片上传所需的参数是否设置正确
338
-        $fileMd5 = $uploadOption->getMd5(); //php 5.3的版本使用empty()传递函数返回值会报错。所以为了兼容,增加临时变量
339
-        if (!$uploadOption->checkMutipartParas() || empty($fileMd5)) {
340
-            return $this->_errorResponse("MultipartCompleteError", "multipart upload's parameters(id,uploadId,md5) error");
341
-        }
342
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
343
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
344
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
345
-    }
338
+		$fileMd5 = $uploadOption->getMd5(); //php 5.3的版本使用empty()传递函数返回值会报错。所以为了兼容,增加临时变量
339
+		if (!$uploadOption->checkMutipartParas() || empty($fileMd5)) {
340
+			return $this->_errorResponse("MultipartCompleteError", "multipart upload's parameters(id,uploadId,md5) error");
341
+		}
342
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
343
+		$uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
344
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
345
+	}
346 346
 
347
-    /**
348
-     * 取消分片上传任务。需要保证UploadOption中有分片任务的uploadId和id
349
-     * @param UploadPolicy $uploadPolicy 上传策略
350
-     * @param UploadOption $uploadOption 上传选项
351
-     * @return array 分片上传完成的结果
352
-     */
353
-    public function multipartCancel(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
354
-    {
355
-        if (!$uploadOption->checkMutipartParas()) {
356
-            return $this->_errorResponse("MultipartCancelError", "multipart upload's parameters(id,uploadId) error");
357
-        }
358
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
359
-        $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
360
-        return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
361
-    }
347
+	/**
348
+	 * 取消分片上传任务。需要保证UploadOption中有分片任务的uploadId和id
349
+	 * @param UploadPolicy $uploadPolicy 上传策略
350
+	 * @param UploadOption $uploadOption 上传选项
351
+	 * @return array 分片上传完成的结果
352
+	 */
353
+	public function multipartCancel(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
354
+	{
355
+		if (!$uploadOption->checkMutipartParas()) {
356
+			return $this->_errorResponse("MultipartCancelError", "multipart upload's parameters(id,uploadId) error");
357
+		}
358
+		$url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
359
+		$uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
360
+		return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
361
+	}
362 362
 
363
-    /**
364
-     * 调用curl利用http上传数据
365
-     * @param string $method
366
-     * @param string $url
367
-     * @param UploadPolicy $uploadPolicy
368
-     * @param UploadOption $uploadOption
369
-     * @return array (isSuccess, ...)
370
-     */
371
-    protected function _send_request($method, $url, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
372
-    {
373
-        $success = false;
374
-        $result = array();
375
-        /**
376
-         * @var resource $ch
377
-         */
378
-        $ch = curl_init();
379
-        try {
380
-            //构建Http请求头和请求体
381
-            $_headers = array('Expect:');
382
-            $token = $this->_getUploadToken($uploadPolicy);
383
-            array_push($_headers, "Authorization: {$token}");
384
-            array_push($_headers, "User-Agent: {$this->_getUserAgent()}");
385
-            $length = 0;
386
-            if (!empty($uploadOption)) {
387
-                list($contentType, $httpBody) = $this->BuildMultipartForm($uploadOption);
388
-                $length = @strlen($httpBody);
389
-                array_push($_headers, "Content-Type: {$contentType}");
390
-                curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody);            //请求体
391
-            }
392
-            array_push($_headers, "Content-Length: {$length}");
393
-            curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
394
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
395
-            curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout);  //持续时长
396
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
397
-            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
398
-            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
399
-            curl_setopt($ch, CURLOPT_URL, $url);
400
-            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
401
-            //设置请求方式(GET或POST等)
402
-            if ($method == 'PUT' || $method == 'POST') {
403
-                curl_setopt($ch, CURLOPT_POST, 1);
404
-            } else {
405
-                curl_setopt($ch, CURLOPT_POST, 0);
406
-            }
407
-            //执行上传,然后获取服务端返回,决定是否重试
408
-            $response = curl_exec($ch);
409
-            if ($response === false && $uploadOption->httpReTry != 0) {
410
-                //如果执行curl失败,且需要重试,则进行重试
411
-                $this->recordCurlErrorLog($ch); //记录最近一次curl执行错误日志
412
-                $response = curl_exec($ch);
413
-            }
414
-            if ($response === false) {
415
-                $this->recordCurlErrorLog($ch); //记录最近一次curl执行错误日志
416
-                $result = $this->_errorResponse("curl error", "curl request failed");
417
-                $result['errno'] = curl_errno($ch); //错误码
418
-            } else {
419
-                //解析返回结果,并判断是否上传成功
420
-                $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
421
-                $success = ($http_code == 200) ? true : false;                  //判断是否上传成功
422
-                $resStr = explode("\r\n\r\n", $response, 2);
423
-                $resBody = isset($resStr[1]) ? $resStr[1] : '';
424
-                $resArray = json_decode($resBody, true);                        //解析得到结果
425
-                $result = (empty($resArray) ? $result : $resArray);
426
-            }
427
-        } catch (Exception $e) {
428
-            $result = $this->_errorResponse("HTTPRequestException#" . $e->getLine(), $e->getMessage());
429
-        }
363
+	/**
364
+	 * 调用curl利用http上传数据
365
+	 * @param string $method
366
+	 * @param string $url
367
+	 * @param UploadPolicy $uploadPolicy
368
+	 * @param UploadOption $uploadOption
369
+	 * @return array (isSuccess, ...)
370
+	 */
371
+	protected function _send_request($method, $url, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
372
+	{
373
+		$success = false;
374
+		$result = array();
375
+		/**
376
+		 * @var resource $ch
377
+		 */
378
+		$ch = curl_init();
379
+		try {
380
+			//构建Http请求头和请求体
381
+			$_headers = array('Expect:');
382
+			$token = $this->_getUploadToken($uploadPolicy);
383
+			array_push($_headers, "Authorization: {$token}");
384
+			array_push($_headers, "User-Agent: {$this->_getUserAgent()}");
385
+			$length = 0;
386
+			if (!empty($uploadOption)) {
387
+				list($contentType, $httpBody) = $this->BuildMultipartForm($uploadOption);
388
+				$length = @strlen($httpBody);
389
+				array_push($_headers, "Content-Type: {$contentType}");
390
+				curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody);            //请求体
391
+			}
392
+			array_push($_headers, "Content-Length: {$length}");
393
+			curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
394
+			curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
395
+			curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout);  //持续时长
396
+			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
397
+			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
398
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
399
+			curl_setopt($ch, CURLOPT_URL, $url);
400
+			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
401
+			//设置请求方式(GET或POST等)
402
+			if ($method == 'PUT' || $method == 'POST') {
403
+				curl_setopt($ch, CURLOPT_POST, 1);
404
+			} else {
405
+				curl_setopt($ch, CURLOPT_POST, 0);
406
+			}
407
+			//执行上传,然后获取服务端返回,决定是否重试
408
+			$response = curl_exec($ch);
409
+			if ($response === false && $uploadOption->httpReTry != 0) {
410
+				//如果执行curl失败,且需要重试,则进行重试
411
+				$this->recordCurlErrorLog($ch); //记录最近一次curl执行错误日志
412
+				$response = curl_exec($ch);
413
+			}
414
+			if ($response === false) {
415
+				$this->recordCurlErrorLog($ch); //记录最近一次curl执行错误日志
416
+				$result = $this->_errorResponse("curl error", "curl request failed");
417
+				$result['errno'] = curl_errno($ch); //错误码
418
+			} else {
419
+				//解析返回结果,并判断是否上传成功
420
+				$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
421
+				$success = ($http_code == 200) ? true : false;                  //判断是否上传成功
422
+				$resStr = explode("\r\n\r\n", $response, 2);
423
+				$resBody = isset($resStr[1]) ? $resStr[1] : '';
424
+				$resArray = json_decode($resBody, true);                        //解析得到结果
425
+				$result = (empty($resArray) ? $result : $resArray);
426
+			}
427
+		} catch (Exception $e) {
428
+			$result = $this->_errorResponse("HTTPRequestException#" . $e->getLine(), $e->getMessage());
429
+		}
430 430
 
431
-        curl_close($ch); //PHP5.3中不支持finally关键字。因此,为了兼容,这里取消finally
432
-        if (!$success) {
433
-            throw new UploadException($result['message'], $http_code);
434
-        }
435
-        $result['isSuccess'] = $success;
436
-        return $result;
437
-    }
431
+		curl_close($ch); //PHP5.3中不支持finally关键字。因此,为了兼容,这里取消finally
432
+		if (!$success) {
433
+			throw new UploadException($result['message'], $http_code);
434
+		}
435
+		$result['isSuccess'] = $success;
436
+		return $result;
437
+	}
438 438
 
439
-    /**
440
-     * uploadPolicy和uploadOption 合法性检查
441
-     * @param UploadPolicy $uploadPolicy 上传策略
442
-     * @param UploadOption $uploadOption 上传选项
443
-     * @return array($isValid, $message)
444
-     */
445
-    protected function checkUploadInfo(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
446
-    {
447
-        $isValid = true;
448
-        $message = null;
449
-        // 1:判断是否设置空间名
450
-        if (empty($uploadPolicy->bucket) && empty($uploadPolicy->namespace)) {
451
-            $isValid = false;
452
-            $message = 'namespace or bucket is empty';
453
-        } elseif (empty($uploadPolicy->name)) {
454
-            // 2:优先使用uploadPolicy中的name,如果为空,则使用uploadOption中的name
455
-            if (empty($uploadOption->name)) {
456
-                $isValid = false;
457
-                $message = "file's name is empty"; // 如果uploadPolicy和uploadOption中的文件名name都为空,则返回错误信息
458
-            }
459
-        }
460
-        if (true === $isValid) {
461
-            // 3:优先使用uploadPolicy中的dir
462
-            if (!empty($uploadPolicy->dir)) {
463
-                if (strpos($uploadPolicy->dir, '/') !== 0) {
464
-                    $uploadPolicy->dir = '/' . $uploadPolicy->dir; //如果dir不为空,且其前面没有以"/"开头,则为其添加
465
-                }
466
-            }
467
-            // 4:如果uploadPolicy中的dir为空,则使用uploadOption中的dir
468
-            if (!empty($uploadOption->dir)) {
469
-                if (strpos($uploadOption->dir, '/') !== 0) {
470
-                    $uploadOption->dir = '/' . $uploadOption->dir; //如果dir不为空,且其前面没有以"/"开头,则为其添加
471
-                }
472
-            }
473
-            // 5:判断用户设置的文件分块大小,是否在指定的范围内。如果不在,则设置为默认Conf::BLOCK_DEFF_SIZE = 2M
474
-            if (($uploadOption->blockSize > Conf::BLOCK_MAX_SIZE) || ($uploadOption->blockSize < Conf::BLOCK_MIN_SIZE)) {
475
-                $uploadOption->blockSize = Conf::BLOCK_DEFF_SIZE;
476
-            }
477
-        }
478
-        return array($isValid, $message);
479
-    }
439
+	/**
440
+	 * uploadPolicy和uploadOption 合法性检查
441
+	 * @param UploadPolicy $uploadPolicy 上传策略
442
+	 * @param UploadOption $uploadOption 上传选项
443
+	 * @return array($isValid, $message)
444
+	 */
445
+	protected function checkUploadInfo(UploadPolicy $uploadPolicy, UploadOption $uploadOption)
446
+	{
447
+		$isValid = true;
448
+		$message = null;
449
+		// 1:判断是否设置空间名
450
+		if (empty($uploadPolicy->bucket) && empty($uploadPolicy->namespace)) {
451
+			$isValid = false;
452
+			$message = 'namespace or bucket is empty';
453
+		} elseif (empty($uploadPolicy->name)) {
454
+			// 2:优先使用uploadPolicy中的name,如果为空,则使用uploadOption中的name
455
+			if (empty($uploadOption->name)) {
456
+				$isValid = false;
457
+				$message = "file's name is empty"; // 如果uploadPolicy和uploadOption中的文件名name都为空,则返回错误信息
458
+			}
459
+		}
460
+		if (true === $isValid) {
461
+			// 3:优先使用uploadPolicy中的dir
462
+			if (!empty($uploadPolicy->dir)) {
463
+				if (strpos($uploadPolicy->dir, '/') !== 0) {
464
+					$uploadPolicy->dir = '/' . $uploadPolicy->dir; //如果dir不为空,且其前面没有以"/"开头,则为其添加
465
+				}
466
+			}
467
+			// 4:如果uploadPolicy中的dir为空,则使用uploadOption中的dir
468
+			if (!empty($uploadOption->dir)) {
469
+				if (strpos($uploadOption->dir, '/') !== 0) {
470
+					$uploadOption->dir = '/' . $uploadOption->dir; //如果dir不为空,且其前面没有以"/"开头,则为其添加
471
+				}
472
+			}
473
+			// 5:判断用户设置的文件分块大小,是否在指定的范围内。如果不在,则设置为默认Conf::BLOCK_DEFF_SIZE = 2M
474
+			if (($uploadOption->blockSize > Conf::BLOCK_MAX_SIZE) || ($uploadOption->blockSize < Conf::BLOCK_MIN_SIZE)) {
475
+				$uploadOption->blockSize = Conf::BLOCK_DEFF_SIZE;
476
+			}
477
+		}
478
+		return array($isValid, $message);
479
+	}
480 480
 
481
-    /**
482
-     * 构建Http请求的Body
483
-     * @param UploadOption $uploadOption
484
-     * @return array (contentType,httpBody)
485
-     */
486
-    protected function BuildMultipartForm(UploadOption $uploadOption)
487
-    {
488
-        $bodyArray = array();
489
-        $mimeBoundary = md5(microtime());
490
-        $paraArray = $uploadOption->getParaArray();
491
-        foreach ($paraArray as $name => $val) {
492
-            if ($name != 'content') {
493
-                array_push($bodyArray, '--' . $mimeBoundary);
494
-                array_push($bodyArray, "Content-Disposition: form-data; name=\"$name\"");
495
-                array_push($bodyArray, 'Content-Type: text/plain; charset=UTF-8');
496
-                array_push($bodyArray, '');
497
-                array_push($bodyArray, $val);
498
-            }
499
-        }
500
-        if (isset($paraArray['content'])) {
501
-            array_push($bodyArray, '--' . $mimeBoundary);
502
-            $fileName = empty($uploadOption->name) ? "temp" : $uploadOption->name;
503
-            array_push($bodyArray, "Content-Disposition: form-data; name=\"content\"; filename=\"{$fileName}\"");
504
-            array_push($bodyArray, "Content-Type: application/octet-stream");
505
-            array_push($bodyArray, '');
506
-            array_push($bodyArray, $paraArray['content']);
507
-        }
481
+	/**
482
+	 * 构建Http请求的Body
483
+	 * @param UploadOption $uploadOption
484
+	 * @return array (contentType,httpBody)
485
+	 */
486
+	protected function BuildMultipartForm(UploadOption $uploadOption)
487
+	{
488
+		$bodyArray = array();
489
+		$mimeBoundary = md5(microtime());
490
+		$paraArray = $uploadOption->getParaArray();
491
+		foreach ($paraArray as $name => $val) {
492
+			if ($name != 'content') {
493
+				array_push($bodyArray, '--' . $mimeBoundary);
494
+				array_push($bodyArray, "Content-Disposition: form-data; name=\"$name\"");
495
+				array_push($bodyArray, 'Content-Type: text/plain; charset=UTF-8');
496
+				array_push($bodyArray, '');
497
+				array_push($bodyArray, $val);
498
+			}
499
+		}
500
+		if (isset($paraArray['content'])) {
501
+			array_push($bodyArray, '--' . $mimeBoundary);
502
+			$fileName = empty($uploadOption->name) ? "temp" : $uploadOption->name;
503
+			array_push($bodyArray, "Content-Disposition: form-data; name=\"content\"; filename=\"{$fileName}\"");
504
+			array_push($bodyArray, "Content-Type: application/octet-stream");
505
+			array_push($bodyArray, '');
506
+			array_push($bodyArray, $paraArray['content']);
507
+		}
508 508
 
509
-        array_push($bodyArray, '--' . $mimeBoundary . '--');
510
-        array_push($bodyArray, '');
509
+		array_push($bodyArray, '--' . $mimeBoundary . '--');
510
+		array_push($bodyArray, '');
511 511
 
512
-        $httpBody = implode("\r\n", $bodyArray);
513
-        $contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
514
-        return array(
515
-            $contentType,
516
-            $httpBody
517
-        );
518
-    }
512
+		$httpBody = implode("\r\n", $bodyArray);
513
+		$contentType = 'multipart/form-data; boundary=' . $mimeBoundary;
514
+		return array(
515
+			$contentType,
516
+			$httpBody
517
+		);
518
+	}
519 519
 
520
-    /**
521
-     * UserAgent用户代理
522
-     */
523
-    protected function _getUserAgent()
524
-    {
525
-        if ($this->type == "TOP") {
526
-            return "ALIMEDIASDK_PHP_TAE/" . Conf::SDK_VERSION;
527
-        } else {
528
-            return "ALIMEDIASDK_PHP_CLOUD/" . Conf::SDK_VERSION;
529
-        }
530
-    }
520
+	/**
521
+	 * UserAgent用户代理
522
+	 */
523
+	protected function _getUserAgent()
524
+	{
525
+		if ($this->type == "TOP") {
526
+			return "ALIMEDIASDK_PHP_TAE/" . Conf::SDK_VERSION;
527
+		} else {
528
+			return "ALIMEDIASDK_PHP_CLOUD/" . Conf::SDK_VERSION;
529
+		}
530
+	}
531 531
 
532
-    public function getUploadToken(UploadPolicy $uploadPolicy)
533
-    {
534
-        return $this->_getUploadToken($uploadPolicy);
535
-    }
532
+	public function getUploadToken(UploadPolicy $uploadPolicy)
533
+	{
534
+		return $this->_getUploadToken($uploadPolicy);
535
+	}
536 536
 
537
-    /**
538
-     * 生成上传凭证
539
-     * @param UploadPolicy $uploadPolicy
540
-     * @return string 上传时的凭证token
541
-     */
542
-    protected function _getUploadToken(UploadPolicy $uploadPolicy)
543
-    {
544
-        $encodedPolicy = EncodeUtils::encodeWithURLSafeBase64(json_encode($uploadPolicy->toArray()));
545
-        $signed = hash_hmac('sha1', $encodedPolicy, $this->sk);
546
-        $tempStr = $this->ak . ":" . $encodedPolicy . ":" . $signed;
547
-        $token = "UPLOAD_AK_" . $this->type . " " . EncodeUtils::encodeWithURLSafeBase64($tempStr);
537
+	/**
538
+	 * 生成上传凭证
539
+	 * @param UploadPolicy $uploadPolicy
540
+	 * @return string 上传时的凭证token
541
+	 */
542
+	protected function _getUploadToken(UploadPolicy $uploadPolicy)
543
+	{
544
+		$encodedPolicy = EncodeUtils::encodeWithURLSafeBase64(json_encode($uploadPolicy->toArray()));
545
+		$signed = hash_hmac('sha1', $encodedPolicy, $this->sk);
546
+		$tempStr = $this->ak . ":" . $encodedPolicy . ":" . $signed;
547
+		$token = "UPLOAD_AK_" . $this->type . " " . EncodeUtils::encodeWithURLSafeBase64($tempStr);
548 548
 
549
-        return $token;
550
-    }
549
+		return $token;
550
+	}
551 551
 
552
-    /**
553
-     * 反馈错误信息
554
-     */
555
-    protected function _errorResponse($code = "UnknownError", $message = "unkonown error", $requestId = null)
556
-    {
557
-        return array(
558
-            "isSuccess" => false,
559
-            "code" => $code,
560
-            "message" => $message,
561
-            "requestId" => $requestId
562
-        );
563
-    }
552
+	/**
553
+	 * 反馈错误信息
554
+	 */
555
+	protected function _errorResponse($code = "UnknownError", $message = "unkonown error", $requestId = null)
556
+	{
557
+		return array(
558
+			"isSuccess" => false,
559
+			"code" => $code,
560
+			"message" => $message,
561
+			"requestId" => $requestId
562
+		);
563
+	}
564 564
 
565
-    /**
566
-     * 记录curl错误日志
567
-     * @param curl-handle $ch curl句柄
568
-     */
569
-    protected function recordCurlErrorLog($ch)
570
-    {
571
-        if (AlibabaImage::$RUN_LEVEL == Conf::RUN_LEVEL_DEBUG) {
572
-            $errno = curl_errno($ch); //错误码
573
-            $info  = curl_getinfo($ch); //curl连接资源句柄的信息
574
-            $info['errno'] = $errno; //添加到连接句柄信息中
575
-            $content = date("Y-m-d H:i:s") . json_encode($info) . "\n";
576
-            $logPath = dirname(__FILE__) . "/" . Conf::CURL_ERR_LOG;
577
-            $this->putContentToFile($content, $logPath);
578
-        }
579
-    }
565
+	/**
566
+	 * 记录curl错误日志
567
+	 * @param curl-handle $ch curl句柄
568
+	 */
569
+	protected function recordCurlErrorLog($ch)
570
+	{
571
+		if (AlibabaImage::$RUN_LEVEL == Conf::RUN_LEVEL_DEBUG) {
572
+			$errno = curl_errno($ch); //错误码
573
+			$info  = curl_getinfo($ch); //curl连接资源句柄的信息
574
+			$info['errno'] = $errno; //添加到连接句柄信息中
575
+			$content = date("Y-m-d H:i:s") . json_encode($info) . "\n";
576
+			$logPath = dirname(__FILE__) . "/" . Conf::CURL_ERR_LOG;
577
+			$this->putContentToFile($content, $logPath);
578
+		}
579
+	}
580 580
 
581
-    /**
582
-     * 将信息追加写到文件
583
-     * @param string $message 日志内容。
584
-     * @return void
585
-     */
586
-    protected function putContentToFile($content, $filepath)
587
-    {
588
-        if (!file_exists($filepath)) {
589
-            $handle = fopen($filepath, 'w');
590
-            fclose($handle);
591
-        }
592
-        file_put_contents($filepath, $content, FILE_APPEND);
593
-    }
581
+	/**
582
+	 * 将信息追加写到文件
583
+	 * @param string $message 日志内容。
584
+	 * @return void
585
+	 */
586
+	protected function putContentToFile($content, $filepath)
587
+	{
588
+		if (!file_exists($filepath)) {
589
+			$handle = fopen($filepath, 'w');
590
+			fclose($handle);
591
+		}
592
+		file_put_contents($filepath, $content, FILE_APPEND);
593
+	}
594 594
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
             return $this->_errorResponse("FileNotExist", "file not exist");
39 39
         }
40 40
         if (empty($uploadOption)) {
41
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
41
+            $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的
42 42
         }
43 43
         if (empty($uploadOption->name)) {
44
-            $uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
44
+            $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名
45 45
         }
46 46
         // UploadPolicy 和 UploadOption检查
47 47
         list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     {
69 69
         $data = file_get_contents($filePath);
70 70
         $uploadOption->setContent($data);
71
-        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
71
+        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API
72 72
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
73 73
     }
74 74
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
      */
82 82
     protected function uploadSuperFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
83 83
     {
84
-        $fileSize = filesize($filePath);        // 文件大小
85
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
84
+        $fileSize = filesize($filePath); // 文件大小
85
+        $blockSize = $uploadOption->blockSize; // 文件分片大小
86 86
         $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
87 87
         for ($i = 0; $i < $blockNum; $i++) {
88 88
             $currentSize = $blockSize; // 当前文件块的大小
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
             $httpRes = null;
96 96
             if (0 == $i) {
97 97
                 // 分片初始化阶段
98
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
99
-                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
98
+                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API
99
+                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型
100 100
                 $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
101 101
                 $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
102 102
                 $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
                 $uploadOption->setUniqueIdId($id);
105 105
             } else {
106 106
                 // 分片上传过程中
107
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
108
-                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
109
-                $uploadOption->setPartNumber($i + 1);                           //
107
+                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API
108
+                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型
109
+                $uploadOption->setPartNumber($i + 1); //
110 110
                 $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
111 111
             }
112 112
             // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
113 113
             if (!$httpRes['isSuccess']) {
114 114
                 if ($uploadOption->checkMutipartParas()) {
115
-                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
116
-                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
115
+                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API
116
+                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型
117 117
                     $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
118 118
                 }
119 119
                 return $httpRes;
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
             $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
127 127
         }
128 128
         // 分片上传完成
129
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
130
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
131
-        $uploadOption->setMd5(md5_file($filePath));                         //文件Md5
129
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API
130
+        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型
131
+        $uploadOption->setMd5(md5_file($filePath)); //文件Md5
132 132
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
133 133
     }
134 134
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
145 145
     {
146 146
         if (empty($uploadOption)) {
147
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
147
+            $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的
148 148
         }
149 149
         // UploadPolicy 和 UploadOption检查
150 150
         list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
         }
159 159
         // 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile()
160 160
         $uploadOption->setContent($data);
161
-        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD;        //普通上传的API
161
+        $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API
162 162
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
163 163
     }
164 164
 
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
      */
172 172
     protected function uploadSuperData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null)
173 173
     {
174
-        $dataSize = strlen($data);          // 文件大小
175
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
174
+        $dataSize = strlen($data); // 文件大小
175
+        $blockSize = $uploadOption->blockSize; // 文件分片大小
176 176
         $blockNum = intval(ceil($dataSize / $blockSize)); // 文件分片后的块数
177 177
         for ($i = 0; $i < $blockNum; $i++) {
178 178
             $currentSize = $blockSize; // 当前文件块的大小
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
             $httpRes = null;
186 186
             if (0 == $i) {
187 187
                 // 分片初始化阶段
188
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
189
-                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
188
+                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API
189
+                $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型
190 190
                 $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
191 191
                 $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
192 192
                 $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id)
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
                 $uploadOption->setUniqueIdId($id);
195 195
             } else {
196 196
                 // 分片上传过程中
197
-                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
198
-                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
199
-                $uploadOption->setPartNumber($i + 1);                           //
197
+                $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API
198
+                $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型
199
+                $uploadOption->setPartNumber($i + 1); //
200 200
                 $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
201 201
             }
202 202
             // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息
203 203
             if (!$httpRes['isSuccess']) {
204 204
                 if ($uploadOption->checkMutipartParas()) {
205
-                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
206
-                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
205
+                    $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API
206
+                    $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型
207 207
                     $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果
208 208
                 }
209 209
                 return $httpRes;
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
             $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
213 213
         }
214 214
         // 分片上传完成
215
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
216
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
217
-        $uploadOption->setMd5(md5($data));                          //文件Md5
215
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API
216
+        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型
217
+        $uploadOption->setMd5(md5($data)); //文件Md5
218 218
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
219 219
     }
220 220
 
@@ -232,10 +232,10 @@  discard block
 block discarded – undo
232 232
             return $this->_errorResponse("FileNotExist", "file not exist");
233 233
         }
234 234
         if (empty($uploadOption)) {
235
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
235
+            $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的
236 236
         }
237 237
         if (empty($uploadOption->name)) {
238
-            $uploadOption->name = basename($filePath);        //如果用户没有设置name属性,则使用上传时的文件名
238
+            $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名
239 239
         }
240 240
         $blockData = file_get_contents($encodePath, 0, null, 0, $uploadOption->blockSize);
241 241
         return $this->multipartInitByData($blockData, $uploadPolicy, $uploadOption);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     public function multipartInitByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption)
252 252
     {
253 253
         if (empty($uploadOption)) {
254
-            $uploadOption = new UploadOption();     //如果用户没有传递UploadOption,则生成一个默认的
254
+            $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的
255 255
         }
256 256
         // UploadPolicy 和 UploadOption检查
257 257
         list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption);
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
             return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message);
260 260
         }
261 261
         // 数据大小不等于设定的分片大小(默认2M),则无法完成初始化
262
-        $dataSize = strlen($blockData);         // 数据文件大小
262
+        $dataSize = strlen($blockData); // 数据文件大小
263 263
         if ($dataSize != ($uploadOption->blockSize)) {
264 264
             return $this->_errorResponse("MultipartInitError", "UploadOption's blockSize is not equal to data's size");
265 265
         }
266 266
         $uploadOption->setContent($blockData); // 设置待上传的文件块
267
-        $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD;    //初始化分片时的Option类型
268
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT;        //初始化分片上传的API
267
+        $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型
268
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API
269 269
         $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
270 270
         //若成功返回,则保存初始化成功的uploadId、id 以及 partNumber、eTag
271 271
         $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id)
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
         if (!file_exists($encodePath)) {
291 291
             return $this->_errorResponse("FileNotExist", "file not exist");
292 292
         }
293
-        $fileSize = filesize($encodePath);      // 文件大小
294
-        $blockSize = $uploadOption->blockSize;  // 文件分片大小
293
+        $fileSize = filesize($encodePath); // 文件大小
294
+        $blockSize = $uploadOption->blockSize; // 文件分片大小
295 295
         $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数
296 296
         $currentSize = $blockSize; // 当前文件块的大小
297 297
         if ($uploadOption->getPartNumber() == $blockNum) {
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
             return $this->_errorResponse("MultipartUploadError", "multipart upload's parameters(id,uploadId,partNumber) error");
318 318
         }
319 319
         $uploadOption->setContent($blockData); // 设置待上传的文件块
320
-        $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD;     //分片上传过程中的Option类型
321
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD;      //分片上传过程中的API
320
+        $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型
321
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API
322 322
         $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
323 323
         if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) {
324 324
             $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']);
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
         if (!$uploadOption->checkMutipartParas() || empty($fileMd5)) {
340 340
             return $this->_errorResponse("MultipartCompleteError", "multipart upload's parameters(id,uploadId,md5) error");
341 341
         }
342
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE;            //完成分片上传任务的API
343
-        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD;        //完成分片上传任务时的Option类型
342
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API
343
+        $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型
344 344
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
345 345
     }
346 346
 
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
         if (!$uploadOption->checkMutipartParas()) {
356 356
             return $this->_errorResponse("MultipartCancelError", "multipart upload's parameters(id,uploadId) error");
357 357
         }
358
-        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL;      //取消分片任务的API
359
-        $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD;  //取消分片任务时的Option类型
358
+        $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API
359
+        $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型
360 360
         return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption);
361 361
     }
362 362
 
@@ -387,17 +387,17 @@  discard block
 block discarded – undo
387 387
                 list($contentType, $httpBody) = $this->BuildMultipartForm($uploadOption);
388 388
                 $length = @strlen($httpBody);
389 389
                 array_push($_headers, "Content-Type: {$contentType}");
390
-                curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody);            //请求体
390
+                curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody); //请求体
391 391
             }
392 392
             array_push($_headers, "Content-Length: {$length}");
393
-            curl_setopt($ch, CURLOPT_HEADER, 1);                            //设置头部
394
-            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers);                //请求头
395
-            curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout);  //持续时长
396
-            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);               //连接超时时长
393
+            curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部
394
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头
395
+            curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout); //持续时长
396
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长
397 397
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE
398 398
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
399 399
             curl_setopt($ch, CURLOPT_URL, $url);
400
-            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);           //自定义请求
400
+            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求
401 401
             //设置请求方式(GET或POST等)
402 402
             if ($method == 'PUT' || $method == 'POST') {
403 403
                 curl_setopt($ch, CURLOPT_POST, 1);
@@ -418,10 +418,10 @@  discard block
 block discarded – undo
418 418
             } else {
419 419
                 //解析返回结果,并判断是否上传成功
420 420
                 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
421
-                $success = ($http_code == 200) ? true : false;                  //判断是否上传成功
421
+                $success = ($http_code == 200) ? true : false; //判断是否上传成功
422 422
                 $resStr = explode("\r\n\r\n", $response, 2);
423 423
                 $resBody = isset($resStr[1]) ? $resStr[1] : '';
424
-                $resArray = json_decode($resBody, true);                        //解析得到结果
424
+                $resArray = json_decode($resBody, true); //解析得到结果
425 425
                 $result = (empty($resArray) ? $result : $resArray);
426 426
             }
427 427
         } catch (Exception $e) {
Please login to merge, or discard this patch.