-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkss_s3_upload.php
76 lines (67 loc) · 2.32 KB
/
kss_s3_upload.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
<?php
# $access_id is your AccessId
# $access_key is your AccessSecretKey
# $key is upload filename
# $bucket_name is your bucketname
# $host is server address
# $url is $host/$bucketname
# $policy is the rule you make for customers
# $policy has success_action_redirect to allow your redirect your address
# $sign is credentials
# policy must include expiration and condition key, condition bucket
# form item except "KSSAccessKeyId", "Signature", "file", "Policy", "bucket", "key",
# must be include in the policy
$access_id = "your AccessId";
$access_key = "your AccessSecretKey";
$bucket_name = "your bucket name";
$redirect = "http://ksyun.com/";
$host = "http://".$bucket_name.".kss.ksyun.com/";
$key = "your file name";
function iso8601($time=false) {
if ($time === false) $time = time();
$date = date('Y-m-d\TH:i:s\.Z', $time);
return (substr($date, 0, strlen($date)-2).'Z');
}
function def_policy(){
global $key;
global $redirect;
$t = time() + (3600*24);
$exp = iso8601($t);
$policy = "{\"expiration\":\"$exp\",
\"conditions\": [
{\"bucket\": \"yourbucketname\"},
[\"starts-with\", \"\$key\", \"$key\"],
[\"content-length-range\", 0, 5000000000 ],
{\"success_action_redirect\": \"$redirect\"},
[\"starts-with\", \"\$Content-Type\", \"text/html\" ],
{\"acl\":\"public-read\"}
]
}";
return $policy;
}
function cal_sign($policy){
global $access_key;
$sign = base64_encode(hash_hmac('sha1',$policy, $access_key, true));
return $sign;
};
$policy = def_policy();
$policy = base64_encode($policy);
$sign = cal_sign($policy);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="<?php echo $host;?>" method="post" enctype="multipart/form-data">
Key to upload: <input type="input" name="key" value="<?php echo $key;?>"/><br />
<input type="hidden" name="KSSAccessKeyId" value="<?php echo $access_id;?>"/>
<input type="hidden" name="Policy" value="<?php echo $policy;?>"/>
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="Signature" value="<?php echo $sign;?>" />
<input type="hidden" name="success_action_redirect" value="<?php echo $redirect;?>" />
<input type="hidden" name="Content-Type" value="text/html" />
File: <input type="file" name="file" /> <br />
<input type="submit" name="submit" value="Upload to KSS S3" />
</form>
</html>