Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;

// 用于签名的公钥和私钥. http://developer.qiniu.com/docs/v6/api/overview/security.html#aksk
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

// 初始化签权对象。
$auth = new Auth($accessKey, $secretKey);
14 changes: 14 additions & 0 deletions examples/bucket_mgr_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);

//初始化BucketManager
$bucketMgr = new BucketManager($auth);
28 changes: 28 additions & 0 deletions examples/file_copy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);

//初始化BucketManager
$bucketMgr = new BucketManager($auth);

//你要测试的空间, 并且这个key在你空间中存在
$bucket = 'Bucket_Name';
$key = 'php-logo.png';

//将文件从文件$key 复制到文件$key2。 可以在不同bucket复制
$key2 = 'php-logo2.png';
$err = $bucketMgr->copy($bucket, $key, $bucket, $key2);
echo "\n====> copy $key to $key2 : \n";
if ($err !== null) {
var_dump($err);
} else {
echo "Success!";
}
27 changes: 27 additions & 0 deletions examples/file_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);

//初始化BucketManager
$bucketMgr = new BucketManager($auth);

//你要测试的空间, 并且这个key在你空间中存在
$bucket = 'Bucket_Name';
$key = 'php-logo.png';

//删除$bucket 中的文件 $key
$err = $bucketMgr->delete($bucket, $key);
echo "\n====> delete $key : \n";
if ($err !== null) {
var_dump($err);
} else {
echo "Success!";
}
28 changes: 28 additions & 0 deletions examples/file_move.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);

//初始化BucketManager
$bucketMgr = new BucketManager($auth);

//你要测试的空间, 并且这个key在你空间中存在
$bucket = 'Bucket_Name';
$key = 'php-logo.png';

//将文件从文件$key 改成文件名$key2。 可以在不同bucket移动
$key3 = 'php-logo3.png';
$err = $bucketMgr->move($bucket, $key2, $bucket, $key3);
echo "\n====> move $key to $key2 : \n";
if ($err !== null) {
var_dump($err);
} else {
echo "Success!";
}
27 changes: 27 additions & 0 deletions examples/file_stat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

//初始化Auth状态:
$auth = new Auth($accessKey, $secretKey);

//初始化BucketManager
$bucketMgr = new BucketManager($auth);

//你要测试的空间, 并且这个key在你空间中存在
$bucket = 'Bucket_Name';
$key = 'php-logo.png';

//获取文件的状态信息
list($ret, $err) = $bucketMgr->stat($bucket, $key);
echo "\n====> $key stat : \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
9 changes: 9 additions & 0 deletions examples/list_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
$auth = new Auth($accessKey, $secretKey);
$bucketMgr = new BucketManager($auth);

// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
// 要列取的空间名称
$bucket = 'Bucket_Name';

// 要列取文件的公共前缀
$prefix = '';

// 上次列举返回的位置标记,作为本次列举的起点信息。
$marker = '';

// 本次列举的条目数
$limit = 3;

// 列举文件
list($iterms, $marker, $err) = $bucketMgr->listFiles($bucket, $prefix, $marker, $limit);
if ($err !== null) {
echo "\n====> list file err: \n";
Expand Down
7 changes: 4 additions & 3 deletions examples/mkzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Qiniu\Auth;
use Qiniu\Processing\PersistentFop;

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

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

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

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

//压缩后的key
$zipKey = 'test.zip';
Expand Down
7 changes: 7 additions & 0 deletions examples/notify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// 获取notify通知的body信息
$notifyBody = file_get_contents('php://input');

// 业务服务器处理通知信息, 这里直接打印在log中
error_log($notifyBody);
11 changes: 7 additions & 4 deletions examples/pfop.php → examples/persistent_fop.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@

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

//转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
$pipeline = 'abc';
$pfop = new PersistentFop($auth, $bucket, $pipeline);
$pipeline = 'pipeline_name';

//转码完成后通知到你的业务服务器。
$notifyUrl = 'http://375dec79.ngrok.com/notify.php';
$pfop = new PersistentFop($auth, $bucket, $pipeline, $notifyUrl);

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

list($id, $err) = $pfop->execute($key, $fops);
echo "\n====> pfop avthumb result: \n";
Expand Down
19 changes: 19 additions & 0 deletions examples/persistent_fop_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Processing\PersistentFop;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);

// 要转码的文件所在的空间。
$bucket = 'Bucket_Name';

// 转码是使用的队列名称。 https://portal.qiniu.com/mps/pipeline
$pipeline = 'pipeline_name';

// 初始化
$pfop = new PersistentFop($auth, $bucket, $pipeline);
12 changes: 12 additions & 0 deletions examples/persistent_fop_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Processing\PersistentFop;

// 触发持久化处理后返回的 Id
$persistentId = 'z0.564d5f977823de48a85ece59';

// 通过persistentId查询该 触发持久化处理的状态
$status = PersistentFop::status($persistentId);

var_dump($status);
2 changes: 1 addition & 1 deletion examples/qetag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

list($etag, $err) = Etag::sum(__file__);
if ($err == null) {
echo("Etag: $etag");
echo "Etag: $etag";
} else {
var_dump($err);
}
39 changes: 39 additions & 0 deletions examples/upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
require_once __DIR__ . '/../autoload.php';

// 引入鉴权类
use Qiniu\Auth;

// 引入上传类
use Qiniu\Storage\UploadManager;

// 需要填写你的 Access Key 和 Secret Key
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';

// 构建鉴权对象
$auth = new Auth($accessKey, $secretKey);

// 要上传的空间
$bucket = 'Bucket_Name';

// 生成上传 Token
$token = $auth->uploadToken($bucket);

// 要上传文件的本地路径
$filePath = './php-logo.png';

// 上传到七牛后保存的文件名
$key = 'my-php-logo.png';

// 初始化 UploadManager 对象并进行文件的上传。
$uploadMgr = new UploadManager();

// 调用 UploadManager 的 putFile 方法进行文件的上传。
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
31 changes: 31 additions & 0 deletions examples/upload_and_callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);

$bucket = 'Bucket_Name';
// 上传文件到七牛后, 七牛将文件名和文件大小回调给业务服务器.
// 可参考文档: http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html
$policy = array(
'callbackUrl' => 'http://your.domain.com/callback.php',
'callbackBody' => 'filename=$(fname)&filesize=$(fsize)'
);
$uptoken = $auth->uploadToken($bucket, null, 3600, $policy);

//上传文件的本地路径
$filePath = './php-logo.png';

$uploadMgr = new UploadManager();

list($ret, $err) = $uploadMgr->putFile($uptoken, null, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
40 changes: 40 additions & 0 deletions examples/upload_and_pfop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);

$bucket = 'Bucket_Name';
// 在七牛保存的文件名
$key = 'php-logo.png';
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();

//上传视频,上传完成后进行m3u8的转码, 并给视频打水印
$wmImg = Qiniu\base64_urlSafeEncode('http://Bucket_Name.qiniudn.com/logo-s.png');
$pfop = "avthumb/m3u8/wmImage/$wmImg";

//转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK)
$notifyUrl = 'http://notify.fake.com';

//独立的转码队列:https://portal.qiniu.com/mps/pipeline
$pipeline = 'pipeline_name';

$policy = array(
'persistentOps' => $pfop,
'persistentNotifyUrl' => $notifyUrl,
'persistentPipeline' => $pipeline
);
$token = $auth->uploadToken($bucket, null, 3600, $policy);

list($ret, $err) = $uploadMgr->putFile($token, null, $key);
echo "\n====> putFile result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
18 changes: 18 additions & 0 deletions examples/upload_mgr_init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
require_once __DIR__ . '/../autoload.php';

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);

// 空间名 http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket
$bucket = 'Bucket_Name';

// 生成上传Token
$token = $auth->uploadToken($bucket);

// 构建 UploadManager 对象
$uploadMgr = new UploadManager();