-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
58 lines (45 loc) · 1.54 KB
/
index.php
File metadata and controls
58 lines (45 loc) · 1.54 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
<?php
declare(strict_types=1);
use PCIT\Plugin\Toolkit\Core;
require __DIR__.'/vendor/autoload.php';
$core = new Core();
$prefix = getenv('INPUT_PREFIX') ? getenv('INPUT_PREFIX').DIRECTORY_SEPARATOR : false;
try {
$cosClient = new Qcloud\Cos\Client([
'region' => getenv('INPUT_REGION'),
'credentials' => [
'appId' => getenv('INPUT_APP_ID'),
'secretId' => getenv('INPUT_SECRET_ID'),
'secretKey' => getenv('INPUT_SECRET_KEY'),
],
]);
$input_files = getenv('INPUT_FILES');
// obj
if (is_object(json_decode($input_files))) {
foreach (json_decode($input_files, true) as $file => $key) {
$key = $prefix ? ($prefix.$key) : $key;
$result = $cosClient->putObject([
'Bucket' => getenv('INPUT_BUCKET'),
'Key' => $key,
'Body' => fopen($file, 'r'),
]);
$core->debug("Upload [ $file ] TO [ $key ]");
$core->debug((string) $result);
}
// array
} else {
$files = explode(',', $input_files);
foreach ($files as $file) {
$key = $prefix ? ($prefix.$file) : $file;
$result = $cosClient->putObject([
'Bucket' => getenv('INPUT_BUCKET'),
'Key' => $key,
'Body' => fopen($file, 'r'),
]);
$core->debug("Upload [ $file ] TO [ $key ]");
$core->debug((string) $result);
}
}
} catch (Throwable $e) {
$core->error($e->__toString());
}