-
Notifications
You must be signed in to change notification settings - Fork 22
/
lib_storage_s3_new.php
93 lines (63 loc) · 2.05 KB
/
lib_storage_s3_new.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$GLOBALS['_storage_hooks']['file_exists'] = 'storage_s3_file_exists';
$GLOBALS['_storage_hooks']['get_file'] = 'storage_s3_get_file';
$GLOBALS['_storage_hooks']['put_file'] = 'storage_s3_put_file';
$GLOBALS['_storage_hooks']['delete_file'] = 'storage_s3_delete_file';
loadlib('s3');
# TO DO: decide whether bucket should be passed around in $more
# (20130529/straup)
########################################################################
function storage_s3_file_exists($path, $more=array()) {
$bucket = storage_s3_bucket();
$rsp = s3_head($bucket, $path);
return $rsp;
}
########################################################################
# not tested (20130529/straup)
function storage_s3_get_file($path, $more=array()){
$bucket = storage_s3_bucket();
$rsp = s3_get($bucket, $path);
return $rsp;
}
########################################################################
function storage_s3_put_file($path, $bytes, $more=array()) {
$defaults = array(
'acl' => 'public-read',
);
$more = array_merge($defaults, $more);
if (isset($more['type'])){
$type = $more['type'];
}
else {
loadlib('mime_type');
$type = mime_type_identify($path);
}
$meta = array(
'date-synced' => time(),
);
$args = array(
'id' => $path,
'acl' => $more['acl'],
'content_type' => $type,
'data' => $bytes,
'meta' => $meta,
);
$rsp = s3_put(storage_s3_bucket(), $put_args);
return $rsp;
}
########################################################################
function storage_s3_delete_file($path, $more=array()){
$bucket = storage_s3_bucket();
$rsp = s3_delete($bucket, $path);
return $rsp;
}
########################################################################
function storage_s3_bucket(){
return array(
'id' => $GLOBALS['cfg']['amazon_s3_bucket_name'],
'key' => $GLOBALS['cfg']['amazon_s3_access_key'],
'secret' => $GLOBALS['cfg']['amazon_s3_secret_key'],
);
}
########################################################################
# the end