Skip to content

Commit

Permalink
Merge pull request #105 from qiniu/develop
Browse files Browse the repository at this point in the history
Release v6.1.12
  • Loading branch information
longbai committed Feb 2, 2015
2 parents c4c5834 + 2dd48db commit 35b583a
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 62 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6
before_script:
- export QINIU_ACCESS_KEY="Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ"
- export QINIU_SECRET_KEY="b5b5vNg5nnkwkPfW5ayicPE_pj6hqgKMQEaWQ6JD"
Expand Down
11 changes: 11 additions & 0 deletions demo/fetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

require_once('../qiniu/rs.php');
require_once('../qiniu/conf.php');

$client = new Qiniu_MacHttpClient(null);
$ret = Qiniu_RS_Fetch($client, 'http://rwxf.qiniucdn.com/1.jpg', 'rwxf', 'qiniu.jpg');

var_dump($ret);


16 changes: 16 additions & 0 deletions demo/get_policy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once('../qiniu/rs.php');
require_once('../qiniu/auth_digest.php');

$gpy = new Qiniu_RS_GetPolicy();

$url = 'http://sslayer.qiniudn.com/dive-into-golang.pptx';
echo $gpy->MakeRequest($url, null);

echo "\n";
$url = 'http://sslayer.qiniudn.com/dive-into-golang.pptx?odconv/pdf';
echo $gpy->MakeRequest($url, null);

echo "\n";
$url = 'http://sslayer.qiniug.com/2.m3u8';
echo $gpy->MakeRequest($url, null);
22 changes: 22 additions & 0 deletions demo/pfop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
require_once('../qiniu/pfop.php');
require_once('../qiniu/http.php');

$client = new Qiniu_MacHttpClient(null);

$pfop = new Qiniu_Pfop();

$pfop->Bucket = 'rwxf';
$pfop->Key = '1.mp4';

$savedKey = 'qiniu.jpg';
$entry = Qiniu_Encode("$pfop->Bucket:$savedKey");
$pfop->Fops = "vframe/jpg/offset/180/w/1000/h/1000/rotate/90|saveas/$entry";

list($ret, $err) = $pfop->MakeRequest($client);
echo "\n\n====> pfop result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}
10 changes: 10 additions & 0 deletions demo/sign_req.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
require_once('../qiniu/auth_digest.php');
require('../qiniu/http.php');

$url = 'https://10fd05306325.a.passageway.io/chgm/aXRpc2F0ZXN0OmdvZ29waGVyLmpwZw==/mime/YXBwbGljYXRpb24vdGVzdA==';
$u = array('path' => $url);
$req = new Qiniu_Request($u, '');
$mac = Qiniu_RequireMac(null);

echo $mac->SignRequest($req, true);
27 changes: 27 additions & 0 deletions demo/up.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

require_once('../qiniu/io.php');
require_once('../qiniu/rs.php');

$bucket = 'rwxf';
$key = 'up.php';
$file = <path_to_local_file>;


$client = new Qiniu_MacHttpClient(null);
$putPolicy = new Qiniu_RS_PutPolicy("$bucket:$key");
$putPolicy->CallbackUrl = 'https://10fd05306325.a.passageway.io';
$putPolicy->CallbackBody = 'key=$(key)&hash=$(etag)';
$upToken = $putPolicy->Token(null);

$putExtra = new Qiniu_PutExtra();
$s = time();
list($ret, $err) = Qiniu_PutFile($upToken, $key, $file, $putExtra);
echo "time elapse:". (time() - $s) . "\n";
echo "====> Qiniu_PutFile result: \n";
if ($err !== null) {
var_dump($err);
} else {
var_dump($ret);
}

96 changes: 42 additions & 54 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ SDK源码地址:<https://github.com/qiniu/php-sdk/tags>

示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand All @@ -85,8 +84,7 @@ if ($err !== null) {

示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand All @@ -112,8 +110,7 @@ if ($err !== null) {

示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand All @@ -139,8 +136,7 @@ if ($err !== null) {

示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand All @@ -167,8 +163,7 @@ if ($err !== null) {
#### 5.1 批量获取文件属性信息
示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand Down Expand Up @@ -196,8 +191,7 @@ if ($err !== null) {
#### 5.2 批量复制文件
示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand Down Expand Up @@ -227,8 +221,7 @@ if ($err !== null) {
#### 5.3 批量删除文件
示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand Down Expand Up @@ -257,8 +250,7 @@ if ($err !== null) {
#### 5.4 批量移动文件
示例代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand Down Expand Up @@ -318,8 +310,7 @@ if ($err !== null) {

服务端生成 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 代码如下:

```
{php}
```php

require_once('qiniu/rs.php');

Expand All @@ -336,8 +327,7 @@ $upToken = $putPolicy->Token(null);

上传字符串

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/io.php');
Expand All @@ -362,8 +352,7 @@ if ($err !== null) {

上传本地文件

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/io.php');
Expand Down Expand Up @@ -393,24 +382,26 @@ if ($err !== null) {

[uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 实际上是用 AccessKey/SecretKey 进行数字签名的上传策略(`Qiniu_RS_PutPolicy`),它控制则整个上传流程的行为。让我们快速过一遍你都能够决策啥:

class Qiniu_RS_PutPolicy
{
public $Scope; // 必选项。可以是 bucketName 或者 bucketName:key
public $CallbackUrl; // 可选
public $CallbackBody; // 可选
public $ReturnUrl; // 可选, 更贴切的名字是 redirectUrl。
public $ReturnBody; // 可选
public $AsyncOps; // 可选
public $EndUser; // 可选
public $Expires; // 可选。默认是 3600 秒
public $PersistentOps; // 可选。
public $PersistentNotifyUrl; // 如果设置了PersistentOps,必须同时设置此项。
public $InsertOnly; // 可选。如果设置为非0值,则无论scope设置为何种形式,都只能以`新增`方式上传,不能覆盖。
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
public $SaveKey; // 可选。自定义资源名格式。
public $MimeLimit; // 可选。限定上传的文件类型。
}
```php
class Qiniu_RS_PutPolicy
{
public $Scope; // 必选项。可以是 bucketName 或者 bucketName:key
public $CallbackUrl; // 可选
public $CallbackBody; // 可选
public $ReturnUrl; // 可选, 更贴切的名字是 redirectUrl。
public $ReturnBody; // 可选
public $AsyncOps; // 可选
public $EndUser; // 可选
public $Expires; // 可选。默认是 3600 秒
public $PersistentOps; // 可选。
public $PersistentNotifyUrl; // 如果设置了PersistentOps,必须同时设置此项。
public $InsertOnly; // 可选。如果设置为非0值,则无论scope设置为何种形式,都只能以`新增`方式上传,不能覆盖。
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
public $SaveKey; // 可选。自定义资源名格式。
public $MimeLimit; // 可选。限定上传的文件类型。
}
```

* `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。**注意: key必须采用utf8编码,如使用非utf8编码访问七牛云存储将反馈错误**
* `callbackUrl` 设定业务服务器的回调地址,这样业务服务器才能感知到上传行为的发生。
Expand All @@ -427,8 +418,7 @@ if ($err !== null) {
### 1.3 断点续上传
示例代码如下

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/resumable_io.php');
Expand Down Expand Up @@ -469,10 +459,12 @@ if ($err !== null) {

示例代码:

$key1 = 'file_name_1';
$domain = 'phpsdk.qiniudn.com';
//$baseUrl 就是您要访问资源的地址
$baseUrl = Qiniu_RS_MakeBaseUrl($domain, $key1);
```php
$key1 = 'file_name_1';
$domain = 'phpsdk.qiniudn.com';
//$baseUrl 就是您要访问资源的地址
$baseUrl = Qiniu_RS_MakeBaseUrl($domain, $key1);
```

其中\<domain\>是bucket所对应的域名。七牛云存储为每一个bucket提供一个默认域名。默认域名可以到[七牛云存储开发者平台](https://portal.qiniu.com/)中,空间设置的域名设置一节查询。用户也可以将自有的域名绑定到bucket上,通过自有域名访问七牛云存储。

Expand All @@ -487,8 +479,7 @@ if ($err !== null) {
注意,尖括号不是必需,代表替换项。
私有下载链接可以使用 SDK 提供的如下方法生成:

```
{php}
```php

require_once('qiniu/rs.php');

Expand Down Expand Up @@ -517,8 +508,7 @@ echo $privateUrl . "\n";
<a name=fop-image-info></a>
#### 1.1 查看图像属性

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/fop.php');
Expand Down Expand Up @@ -549,8 +539,7 @@ echo $imgInfoPrivateUrl . "\n";
<a name=fop-exif></a>
#### 1.2 查看图片EXIF信息

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/fop.php');
Expand Down Expand Up @@ -578,8 +567,7 @@ echo $imgExifPrivateUrl . "\n";
<a name=fop-image-view></a>
#### 1.3 生成图片预览

```
{php}
```php

require_once('qiniu/rs.php');
require_once('qiniu/fop.php');
Expand Down
5 changes: 3 additions & 2 deletions qiniu/conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
global $QINIU_UP_HOST;
global $QINIU_RS_HOST;
global $QINIU_RSF_HOST;

global $QINIU_ACCESS_KEY;
global $QINIU_SECRET_KEY;

Expand All @@ -13,7 +13,8 @@
$QINIU_UP_HOST = 'http://upload.qiniu.com';
$QINIU_RS_HOST = 'http://rs.qbox.me';
$QINIU_RSF_HOST = 'http://rsf.qbox.me';
$QINIU_API_HOST = 'http://api.qiniu.com';
$QINIU_IOVIP_HOST = 'http://iovip.qbox.me';

$QINIU_ACCESS_KEY = '<Please apply your access key>';
$QINIU_SECRET_KEY = '<Dont send your secret key to anyone>';

5 changes: 1 addition & 4 deletions qiniu/io.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ function Qiniu_PutFile($upToken, $key, $localFile, $putExtra) // => ($putRet, $e
}

$fields = array('token' => $upToken, 'file' => createFile($localFile, $putExtra->MimeType));
if ($key === null) {
$fname = '?';
} else {
$fname = $key;
if ($key !== null) {
$fields['key'] = $key;
}
if ($putExtra->CheckCrc) {
Expand Down
Loading

0 comments on commit 35b583a

Please sign in to comment.