-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathForm.php
More file actions
46 lines (40 loc) · 1.29 KB
/
Form.php
File metadata and controls
46 lines (40 loc) · 1.29 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
<?php
namespace Upyun\Api;
use Upyun\Signature;
use Upyun\Util;
use GuzzleHttp\Client;
class Form extends Rest
{
public function upload($path, $stream, $params)
{
$params['save-key'] = $path;
$params['bucket'] = $this->config->bucketName;
if (!isset($params['expiration'])) {
$params['expiration'] = time() + 30 * 60 * 60; // 30 分钟
}
$policy = Util::base64Json($params);
$method = 'POST';
$signature = Signature::getBodySignature($this->config, $method, '/' . $params['bucket'], null, $policy);
$client = new Client([
'timeout' => $this->config->timeout,
]);
$url = ($this->config->useSsl ? 'https://' : 'http://') . $this->endpoint;
$response = $client->request($method, $url, array(
'multipart' => array(
array(
'name' => 'policy',
'contents' => $policy,
),
array(
'name' => 'authorization',
'contents' => $signature,
),
array(
'name' => 'file',
'contents' => $stream,
)
)
));
return $response->getStatusCode() === 200;
}
}