File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -171,18 +171,28 @@ public function has($path)
171
171
* 获取云存储文件/目录的基本信息
172
172
*
173
173
* @param string $path 云存储的文件路径
174
+ * @param array $otherHeaders 设置了后,方法将返回其他 http header 中的信息,默认为空
174
175
*
175
176
* @return array 返回一个数组,包含以下 key
176
177
* - `x-upyun-file-type` 当 $path 是目录时,值为 *folder*,当 $path 是文件时,值为 *file*,
177
178
* - `x-upyun-file-size` 文件大小
178
179
* - `x-upyun-file-date` 文件的创建时间
179
180
*/
180
- public function info ($ path )
181
+ public function info ($ path, $ otherHeaders = array () )
181
182
{
182
183
$ req = new Rest ($ this ->config );
183
184
$ response = $ req ->request ('HEAD ' , $ path )
184
185
->send ();
185
- return Util::getHeaderParams ($ response ->getHeaders ());
186
+ return Util::getHeaderParams ($ response ->getHeaders (), $ otherHeaders );
187
+ }
188
+
189
+ public function getMimetype ($ path )
190
+ {
191
+ $ params = $ this ->info ($ path , array ('content-type ' ));
192
+ if (isset ($ params ['content-type ' ])) {
193
+ return explode ('; ' , $ params ['content-type ' ])[0 ];
194
+ }
195
+ return '' ;
186
196
}
187
197
188
198
/**
Original file line number Diff line number Diff line change @@ -12,13 +12,16 @@ public static function trim($str)
12
12
}
13
13
}
14
14
15
- public static function getHeaderParams ($ headers )
15
+ public static function getHeaderParams ($ headers, $ otherParams = array () )
16
16
{
17
17
$ params = [];
18
+ $ otherParams = array_map ('strtolower ' , $ otherParams );
18
19
foreach ($ headers as $ header => $ value ) {
19
20
$ header = strtolower ($ header );
20
21
if (strpos ($ header , 'x-upyun- ' ) !== false ) {
21
22
$ params [$ header ] = $ value [0 ];
23
+ } else if (in_array ($ header , $ otherParams )) {
24
+ $ params [$ header ] = $ value [0 ];
22
25
}
23
26
}
24
27
return $ params ;
Original file line number Diff line number Diff line change @@ -152,6 +152,15 @@ public function testInfo()
152
152
$ this ->assertEquals ($ info ['x-upyun-file-size ' ], 19 );
153
153
}
154
154
155
+ /**
156
+ * @depends testInfo
157
+ */
158
+ public function testGetMimetype ()
159
+ {
160
+ $ type = self ::$ upyun ->getMimetype ('test-info.txt ' );
161
+ $ this ->assertEquals ($ type , 'text/plain ' );
162
+ }
163
+
155
164
/**
156
165
*/
157
166
public function testCreateDir ()
You can’t perform that action at this time.
0 commit comments