Skip to content

Commit b7f3e33

Browse files
committed
add pfop demo and up demo
1 parent 3048719 commit b7f3e33

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed

1.mp4

11.8 MB
Binary file not shown.

encode.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
require_once('qiniu/utils.php');
3+
require_once('qiniu/auth_digest.php');
4+
5+
6+
function makeSaveasUrl($url, $bucket, $key)
7+
{
8+
9+
$entry = Qiniu_Encode("$bucket:$key");
10+
$url .= '|saveas/' . $entry;
11+
12+
$urlPased = parse_url($url);
13+
14+
$mac = Qiniu_RequireMac();
15+
$data = $urlPased['host'] . $urlPased['path'] . '?' . $urlPased['query'];
16+
$sign = $mac->Sign($data);
17+
18+
return $url + '/sign/' . $sign;
19+
}
20+
21+
$url = 'http://auditlog.qiniudn.com/1.jpg?imageMogr2/auto-orient/rotate/45';
22+
$bucket = 'auditlog';
23+
$key = 'rotate.jpg';
24+
25+
echo makeSaveasUrl($url, $bucket, $key);

pfop_demo.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
require_once('qiniu/pfop.php');
3+
require_once('qiniu/http.php');
4+
5+
$client = new Qiniu_MacHttpClient(null);
6+
7+
$pfop = new Qiniu_Pfop();
8+
9+
$pfop->Bucket = "auditlog";
10+
$pfop->Key = "1.mp4";
11+
// $pfop->Fops = "avthumb/flv/r/24/vcodec/libx264";
12+
$pfop->Fops = "avthumb/m3u8/segtime/1";
13+
$pfop->NotifyURL = "http://api.rwfeng.com/index.php";
14+
15+
list($ret, $err) = $pfop->MakeRequest($client);
16+
17+
echo "===========>>Ret:";
18+
var_dump($ret);
19+
20+
21+
echo "===========>>Err:";
22+
var_dump($err);

pfop_query.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
require_once('qiniu/pfop.php');
3+
require_once('qiniu/http.php');
4+
5+
$client = new Qiniu_MacHttpClient(null);
6+
7+
if ($_SERVER["argc"] < 2) {
8+
echo 'Usage: php pfop_query.php <id>' . "\n";
9+
exit();
10+
}
11+
12+
$id = $_SERVER["argv"][1];
13+
list($ret, $err) = Qiniu_PfopStatus($client, $id);
14+
15+
echo "===================>>Ret:\n";
16+
var_dump($ret);
17+
18+
echo "===================>>Err:\n";
19+
var_dump($err);
20+
exit(); # code...

qiniu/pfop.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
require_once('auth_digest.php');
3+
4+
// --------------------------------------------------------------------------------
5+
// class Qiniu_ImageView
6+
7+
class Qiniu_Pfop {
8+
9+
public $Bucket;
10+
public $Key;
11+
public $Fops;
12+
public $NotifyURL;
13+
public $Force;
14+
15+
public function MakeRequest($self)
16+
{
17+
18+
global $QINIU_API_HOST;
19+
20+
$ReqParams = array(
21+
'bucket' => $this->Bucket,
22+
'key' => $this->Key,
23+
'fops' => $this->Fops,
24+
'notifyURL' => $this->NotifyURL,
25+
'force' => $this->Force
26+
);
27+
28+
$url = $QINIU_API_HOST . '/pfop/';
29+
30+
return Qiniu_Client_CallWithForm($self, $url, $ReqParams);
31+
}
32+
33+
}
34+
35+
function Qiniu_PfopStatus($client, $id)
36+
{
37+
global $QINIU_API_HOST;
38+
39+
$url = $QINIU_API_HOST . '/status/get/prefop?';
40+
$params = array("id" => $id);
41+
42+
return Qiniu_Client_CallWithForm($client, $url, $params);
43+
}
44+
45+
46+

saveas.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
require_once('qiniu/utils.php');
3+
require_once('qiniu/auth_digest.php');
4+
5+
6+
function makeSaveasUrl($url, $bucket, $key)
7+
{
8+
9+
$entry = Qiniu_Encode("$bucket:$key");
10+
$url .= '|saveas/' . $entry;
11+
12+
$urlPased = parse_url($url);
13+
14+
$mac = Qiniu_RequireMac(null);
15+
$data = $urlPased['host'] . $urlPased['path'] . '?' . $urlPased['query'];
16+
$sign = $mac->Sign($data);
17+
18+
return $url . '/sign/' . $sign;
19+
}
20+
21+
$url = 'http://auditlog.qiniudn.com/1.jpg?imageMogr2/auto-orient/rotate/45';
22+
$bucket = 'auditlog';
23+
$key = 'rotate.jpg';
24+
25+
echo makeSaveasUrl($url, $bucket, $key) . "\n";

up_demo.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
require_once('qiniu/io.php');
4+
require_once('qiniu/rs.php');
5+
6+
$bucket = 'auditlog';
7+
$key1 = 'rwf';
8+
$file = '../php-sdk/1.mp4';
9+
10+
11+
$client = new Qiniu_MacHttpClient(null);
12+
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
13+
$upToken = $putPolicy->Token(null);
14+
15+
$putExtra = new Qiniu_PutExtra();
16+
$putExtra->Crc32 = 1;
17+
list($ret, $err) = Qiniu_PutFile($upToken, $key1, $file, $putExtra);
18+
echo "\n\n====> Qiniu_PutFile result: \n";
19+
if ($err !== null) {
20+
var_dump($err);
21+
} else {
22+
var_dump($ret);
23+
}
24+

up_demo2.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
<html>
4+
<head>
5+
<title>demo-php-form-upload</title>
6+
</head>
7+
<body>
8+
<form method="post" action="http://up.qiniu.com/">
9+
enctype="multipart/form-data">
10+
<input name="key" type="hidden" value="<resource_key>">
11+
<input name="x:<custom_name>" type="hidden" value="<custom_value>">
12+
<input name="token" type="hidden" value="<upload_token>">
13+
<input name="file" type="file" />
14+
</form>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)