Skip to content

Commit 9ed22ec

Browse files
committed
Merge pull request #93 from rwifeng/demo
Demo
2 parents 5449d07 + 660461d commit 9ed22ec

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

demo/download_token.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
require_once('../qiniu/utils.php');
3+
require_once('../qiniu/auth_digest.php');
4+
5+
function dnToken($url, $expires = 3600)
6+
{
7+
8+
$e = 'e=' . (time() + $expires);
9+
10+
$qry = parse_url($url, PHP_URL_QUERY);
11+
if ($qry) {
12+
$url .= '&' . $e;
13+
} else {
14+
$url .= '?' . $e;
15+
}
16+
17+
$sign = Qiniu_Sign(null, $url);
18+
19+
return $url . '&token=' . $sign;
20+
}
21+
22+
$url = 'http://sslayer.qiniudn.com/dive-into-golang.pptx';
23+
echo dnToken($url);
24+
25+
echo "\n";
26+
$url = 'http://sslayer.qiniudn.com/dive-into-golang.pptx?odconv/pdf';
27+
echo dnToken($url);

demo/up.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55

66
$bucket = 'rwxf';
77
$key = 'up.php';
8-
$file = __FILE__;
8+
$file = __FILE__; //path to local file
99

1010

1111
$client = new Qiniu_MacHttpClient(null);
12-
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
13-
$putPolicy->Scope = "$bucket:$key";
12+
$putPolicy = new Qiniu_RS_PutPolicy("$bucket:$key");
1413
$putPolicy->CallbackUrl = 'https://10fd05306325.a.passageway.io';
1514
$putPolicy->CallbackBody = 'key=$(key)&hash=$(etag)';
1615
$upToken = $putPolicy->Token(null);
1716

1817
$putExtra = new Qiniu_PutExtra();
19-
$putExtra->Crc32 = 1;
2018
$s = time();
2119
list($ret, $err) = Qiniu_PutFile($upToken, $key, $file, $putExtra);
2220
echo "time elapse:". (time() - $s) . "\n";
23-
echo "\n\n====> Qiniu_PutFile result: \n";
21+
echo "====> Qiniu_PutFile result: \n";
2422
if ($err !== null) {
2523
var_dump($err);
2624
} else {

0 commit comments

Comments
 (0)