Skip to content

Commit 550cc98

Browse files
committed
Merge pull request #171 from rwifeng/add_demos
Add demos
2 parents bf1ead8 + 50e3375 commit 550cc98

17 files changed

+322
-8
lines changed

examples/auth.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
6+
// 用于签名的公钥和私钥. http://developer.qiniu.com/docs/v6/api/overview/security.html#aksk
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
// 初始化签权对象。
11+
$auth = new Auth($accessKey, $secretKey);

examples/bucket_mgr_init.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
//初始化Auth状态:
11+
$auth = new Auth($accessKey, $secretKey);
12+
13+
//初始化BucketManager
14+
$bucketMgr = new BucketManager($auth);

examples/file_copy.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
//初始化Auth状态:
11+
$auth = new Auth($accessKey, $secretKey);
12+
13+
//初始化BucketManager
14+
$bucketMgr = new BucketManager($auth);
15+
16+
//你要测试的空间, 并且这个key在你空间中存在
17+
$bucket = 'Bucket_Name';
18+
$key = 'php-logo.png';
19+
20+
//将文件从文件$key 复制到文件$key2。 可以在不同bucket复制
21+
$key2 = 'php-logo2.png';
22+
$err = $bucketMgr->copy($bucket, $key, $bucket, $key2);
23+
echo "\n====> copy $key to $key2 : \n";
24+
if ($err !== null) {
25+
var_dump($err);
26+
} else {
27+
echo "Success!";
28+
}

examples/file_delete.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
//初始化Auth状态:
11+
$auth = new Auth($accessKey, $secretKey);
12+
13+
//初始化BucketManager
14+
$bucketMgr = new BucketManager($auth);
15+
16+
//你要测试的空间, 并且这个key在你空间中存在
17+
$bucket = 'Bucket_Name';
18+
$key = 'php-logo.png';
19+
20+
//删除$bucket 中的文件 $key
21+
$err = $bucketMgr->delete($bucket, $key);
22+
echo "\n====> delete $key : \n";
23+
if ($err !== null) {
24+
var_dump($err);
25+
} else {
26+
echo "Success!";
27+
}

examples/file_move.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
//初始化Auth状态:
11+
$auth = new Auth($accessKey, $secretKey);
12+
13+
//初始化BucketManager
14+
$bucketMgr = new BucketManager($auth);
15+
16+
//你要测试的空间, 并且这个key在你空间中存在
17+
$bucket = 'Bucket_Name';
18+
$key = 'php-logo.png';
19+
20+
//将文件从文件$key 改成文件名$key2。 可以在不同bucket移动
21+
$key3 = 'php-logo3.png';
22+
$err = $bucketMgr->move($bucket, $key2, $bucket, $key3);
23+
echo "\n====> move $key to $key2 : \n";
24+
if ($err !== null) {
25+
var_dump($err);
26+
} else {
27+
echo "Success!";
28+
}

examples/file_stat.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
10+
//初始化Auth状态:
11+
$auth = new Auth($accessKey, $secretKey);
12+
13+
//初始化BucketManager
14+
$bucketMgr = new BucketManager($auth);
15+
16+
//你要测试的空间, 并且这个key在你空间中存在
17+
$bucket = 'Bucket_Name';
18+
$key = 'php-logo.png';
19+
20+
//获取文件的状态信息
21+
list($ret, $err) = $bucketMgr->stat($bucket, $key);
22+
echo "\n====> $key stat : \n";
23+
if ($err !== null) {
24+
var_dump($err);
25+
} else {
26+
var_dump($ret);
27+
}

examples/list_file.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@
99
$auth = new Auth($accessKey, $secretKey);
1010
$bucketMgr = new BucketManager($auth);
1111

12+
// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
13+
// 要列取的空间名称
1214
$bucket = 'Bucket_Name';
15+
16+
// 要列取文件的公共前缀
1317
$prefix = '';
18+
19+
// 上次列举返回的位置标记,作为本次列举的起点信息。
1420
$marker = '';
21+
22+
// 本次列举的条目数
1523
$limit = 3;
1624

25+
// 列举文件
1726
list($iterms, $marker, $err) = $bucketMgr->listFiles($bucket, $prefix, $marker, $limit);
1827
if ($err !== null) {
1928
echo "\n====> list file err: \n";

examples/mkzip.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Qiniu\Auth;
55
use Qiniu\Processing\PersistentFop;
66

7+
// 去我们的portal 后台来获取AK, SK
78
$accessKey = 'Access_Key';
89
$secretKey = 'Secret_Key';
910
$auth = new Auth($accessKey, $secretKey);
@@ -13,13 +14,13 @@
1314
$key = '1.png';
1415

1516
// 异步任务的队列, 去后台新建: https://portal.qiniu.com/mps/pipeline
16-
$pipeline = 'abc';
17+
$pipeline = 'pipeline_name';
1718

1819
$pfop = new PersistentFop($auth, $bucket, $pipeline);
1920

2021
// 进行zip压缩的url
21-
$url1 = 'http://Bucket_Name.qiniudn.com/php-logo.png';
22-
$url2 = 'http://Bucket_Name.qiniudn.com/php-sdk.html';
22+
$url1 = 'http://rwxf.qiniudn.com/php-logo.png';
23+
$url2 = 'http://rwxf.qiniudn.com/1.png';
2324

2425
//压缩后的key
2526
$zipKey = 'test.zip';

examples/notify.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// 获取notify通知的body信息
4+
$notifyBody = file_get_contents('php://input');
5+
6+
// 业务服务器处理通知信息, 这里直接打印在log中
7+
error_log($notifyBody);

examples/pfop.php renamed to examples/persistent_fop.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313
//要转码的文件所在的空间和文件名。
1414
$bucket = 'Bucket_Name';
15-
$key = '1.mp4';
15+
$key = 'File_Name_On_Qiniu';
1616

1717
//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
18-
$pipeline = 'abc';
19-
$pfop = new PersistentFop($auth, $bucket, $pipeline);
18+
$pipeline = 'pipeline_name';
19+
20+
//转码完成后通知到你的业务服务器。
21+
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
22+
$pfop = new PersistentFop($auth, $bucket, $pipeline, $notifyUrl);
2023

2124
//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html
22-
$fops = "avthumb/mp4/s/640x360/vb/1.25m";
25+
$fops = "avthumb/mp4/s/640x360/vb/1.4m";
2326

2427
list($id, $err) = $pfop->execute($key, $fops);
2528
echo "\n====> pfop avthumb result: \n";

0 commit comments

Comments
 (0)