forked from webkb/php_object_storage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathucloud.php
More file actions
60 lines (54 loc) · 1.56 KB
/
Copy pathucloud.php
File metadata and controls
60 lines (54 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
define('UCLOUD_ACCESSKEYID', '');
define('UCLOUD_ACCESSKEYSECRET', '');
define('UCLOUD_BUCKET', '');
define('UCLOUD_HOST', '');
function UCloud对象存储($method, $filename = '', $file = '', $query = '') {
$accessKeyId = UCLOUD_ACCESSKEYID;
$accessKeySecret = UCLOUD_ACCESSKEYSECRET;
$bucket = UCLOUD_BUCKET;
$domain = UCLOUD_HOST;
$url = "http://$bucket.$domain/$filename$query";
if ($file) {
$mime = mime_content_type($file);
} else {
$mime = '';
}
$options = join("\n", array(
strtoupper($method),
'',
$mime,
'',
"/$bucket/$filename"
));
$hash = hash_hmac(
'sha1',
$options,
$accessKeySecret,
true
);
$auth = $accessKeyId . ':' . base64_encode($hash);
$headers = array(
"Expect: ",
"Content-Type: $mime",
"Authorization: UCloud $auth"
);
if ($file) {
$postfileds = file_get_contents($file);
return curl($url, $headers, $method, '', $postfileds);
} else {
return curl($url, $headers, $method);
}
}
function UCloud对象存储上传 ($file, $filename) {
return UCloud对象存储('PUT', $filename, $file);
}
function UCloud对象存储删除 ($filename) {
return UCloud对象存储('DELETE', $filename);
}
function UCloud对象存储列表 ($query = '?list') {
$jsonlist = UCloud对象存储('GET', '', '', $query);
$objectlist = json_decode($jsonlist);
$objectlist->Contents = $objectlist->DataSet; unset($objectlist->DataSet);
return $objectlist;
}