Skip to content

Commit b2fdb4b

Browse files
committed
split examples
1 parent 3cfe0f7 commit b2fdb4b

17 files changed

+324
-10
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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
use Qiniu\Auth;
55
use Qiniu\Processing\PersistentFop;
66

7-
$accessKey = 'Access_Key';
8-
$secretKey = 'Secret_Key';
7+
// 去我们的portal 后台来获取AK, SK
8+
$accessKey = '4brtJLyWA3bplJKlkn7ZypPbzKcS-58MsF1cnsF4';
9+
$secretKey = 'jt8qbHTrBFAl6HZNt9Mmd2pcx122aJlJ-5mgS-7g';
910
$auth = new Auth($accessKey, $secretKey);
1011

1112

12-
$bucket = 'Bucket_Name';
13+
$bucket = 'rwxf';
1314
$key = '1.png';
1415

1516
// 异步任务的队列, 去后台新建: https://portal.qiniu.com/mps/pipeline
@@ -18,8 +19,8 @@
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";

examples/persistent_fop_init.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../autoload.php';
4+
5+
use Qiniu\Auth;
6+
use Qiniu\Processing\PersistentFop;
7+
8+
$accessKey = 'Access_Key';
9+
$secretKey = 'Secret_Key';
10+
$auth = new Auth($accessKey, $secretKey);
11+
12+
// 要转码的文件所在的空间。
13+
$bucket = 'Bucket_Name';
14+
15+
// 转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
16+
$pipeline = 'pipeline_name';
17+
18+
// 初始化
19+
$pfop = new PersistentFop($auth, $bucket, $pipeline);

examples/persistent_fop_status.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Processing\PersistentFop;
5+
6+
// 触发持久化处理后返回的 Id
7+
$persistentId = 'z0.564d5f977823de48a85ece59';
8+
9+
// 通过persistentId查询该 触发持久化处理的状态
10+
$status = PersistentFop::status($persistentId);
11+
12+
var_dump($status);

examples/qetag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
list($etag, $err) = Etag::sum(__file__);
66
if ($err == null) {
7-
echo("Etag: $etag");
7+
echo "Etag: $etag";
88
} else {
99
var_dump($err);
1010
}

examples/upload.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
// 引入鉴权类
5+
use Qiniu\Auth;
6+
7+
// 引入上传类
8+
use Qiniu\Storage\UploadManager;
9+
10+
// 需要填写你的 Access Key 和 Secret Key
11+
$accessKey = 'Access_Key';
12+
$secretKey = 'Secret_Key';
13+
14+
// 构建鉴权对象
15+
$auth = new Auth($accessKey, $secretKey);
16+
17+
// 要上传的空间
18+
$bucket = 'Bucket_Name';
19+
20+
// 生成上传 Token
21+
$token = $auth->uploadToken($bucket);
22+
23+
// 要上传文件的本地路径
24+
$filePath = './php-logo.png';
25+
26+
// 上传到七牛后保存的文件名
27+
$key = 'my-php-logo.png';
28+
29+
// 初始化 UploadManager 对象并进行文件的上传。
30+
$uploadMgr = new UploadManager();
31+
32+
// 调用 UploadManager 的 putFile 方法进行文件的上传。
33+
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
34+
echo "\n====> putFile result: \n";
35+
if ($err !== null) {
36+
var_dump($err);
37+
} else {
38+
var_dump($ret);
39+
}

examples/upload_and_callback.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\UploadManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
$auth = new Auth($accessKey, $secretKey);
10+
11+
$bucket = 'Bucket_Name';
12+
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
13+
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
14+
$policy = array(
15+
'callbackUrl' => 'http://your.domain.com/callback.php',
16+
'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
17+
);
18+
$uptoken = $auth->uploadToken($bucket, null, 3600, $policy);
19+
20+
//上传文件的本地路径
21+
$filePath = './php-logo.png';
22+
23+
$uploadMgr = new UploadManager();
24+
25+
list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath);
26+
echo "\n====> putFile result: \n";
27+
if ($err !== null) {
28+
var_dump($err);
29+
} else {
30+
var_dump($ret);
31+
}

examples/upload_and_pfop.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\UploadManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
$auth = new Auth($accessKey, $secretKey);
10+
11+
$bucket = 'Bucket_Name';
12+
// 在七牛保存的文件名
13+
$key = 'php-logo.png';
14+
$token = $auth->uploadToken($bucket);
15+
$uploadMgr = new UploadManager();
16+
17+
//上传视频,上传完成后进行m3u8的转码, 并给视频打水印
18+
$wmImg = Qiniu\base64_urlSafeEncode('http://Bucket_Name.qiniudn.com/logo-s.png');
19+
$pfop = "avthumb/m3u8/wmImage/$wmImg";
20+
21+
//转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK)
22+
$notifyUrl = 'http://notify.fake.com';
23+
24+
//独立的转码队列:https://portal.qiniu.com/mps/pipeline
25+
$pipeline = 'pipeline_name';
26+
27+
$policy = array(
28+
'persistentOps' => $pfop,
29+
'persistentNotifyUrl' => $notifyUrl,
30+
'persistentPipeline' => $pipeline
31+
);
32+
$token = $auth->uploadToken($bucket, null, 3600, $policy);
33+
34+
list($ret, $err) = $uploadMgr->putFile($token, null, $key);
35+
echo "\n====> putFile result: \n";
36+
if ($err !== null) {
37+
var_dump($err);
38+
} else {
39+
var_dump($ret);
40+
}

examples/upload_mgr_init.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\UploadManager;
6+
7+
$accessKey = 'Access_Key';
8+
$secretKey = 'Secret_Key';
9+
$auth = new Auth($accessKey, $secretKey);
10+
11+
// 空间名 http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket
12+
$bucket = 'Bucket_Name';
13+
14+
// 生成上传Token
15+
$token = $auth->uploadToken($bucket);
16+
17+
// 构建 UploadManager 对象
18+
$uploadMgr = new UploadManager();

0 commit comments

Comments
 (0)