forked from tencentyun/cos-php-sdk-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.php
86 lines (70 loc) · 1.82 KB
/
sample.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
<?php
require('./include.php');
use QCloud\Cos\Api;
//bucketname
$bucket = 'testbucket';
//uploadlocalpath
$src = './hello.txt';
//cospath
$dst = '/testfolder/hello.txt';
//downloadlocalpath
$dst2 = 'hello2.txt';
//cosfolderpath
$folder = '/testfolder';
//config your information
$config = array(
'app_id' => '',
'secret_id' => '',
'secret_key' => '',
'region' => '', // bucket所属地域:华北 'tj' 华东 'sh' 华南 'gz'
'timeout' => 60
);
date_default_timezone_set('PRC');
$cosApi = new Api($config);
// Create folder in bucket.
$ret = $cosApi->createFolder($bucket, $folder);
var_dump($ret);
// Upload file into bucket.
$ret = $cosApi->upload($bucket, $src, $dst);
var_dump($ret);
// Download file
$ret = $cosApi->download($bucket, $dst, $dst2);
var_dump($ret);
unlink($dst2);
// List folder.
$ret = $cosApi->listFolder($bucket, $folder);
var_dump($ret);
// Update folder information.
$bizAttr = "";
$ret = $cosApi->updateFolder($bucket, $folder, $bizAttr);
var_dump($ret);
// Update file information.
$bizAttr = '';
$authority = 'eWPrivateRPublic';
$customerHeaders = array(
'Cache-Control' => 'no',
'Content-Type' => 'application/pdf',
'Content-Language' => 'ch',
);
$ret = $cosApi->update($bucket, $dst, $bizAttr,$authority, $customerHeaders);
var_dump($ret);
// Stat folder.
$ret = $cosApi->statFolder($bucket, $folder);
var_dump($ret);
// Stat file.
$ret = $cosApi->stat($bucket, $dst);
var_dump($ret);
// Copy file.
$ret = $cosApi->copyFile($bucket, $dst, $dst . '_copy');
var_dump($ret);
// Move file.
$ret = $cosApi->moveFile($bucket, $dst, $dst . '_move');
var_dump($ret);
// Delete file.
$ret = $cosApi->delFile($bucket, $dst . '_copy');
var_dump($ret);
$ret = $cosApi->delFile($bucket, $dst . '_move');
var_dump($ret);
// Delete folder.
$ret = $cosApi->delFolder($bucket, $folder);
var_dump($ret);